do01
do01

do01

اضافه کردن my_env به پروژه ای در PyCharm

برای اضافه کردن محیط ایزوله پایتون که همه ماژول های مورد نظر رو دارید و نمیخواید از نو بسازید و فقط میخواید که یه پروژه خاص از همین محیط مجازی که ساختید استفاده کنه . مراحل به شکل زیر خواهد بود.


Configure PyCharm

  • Select File, click Settings.
  • In the left pane, enter Project Interpreter in the search box, then click Project Interpreter.
  • In the right pane, click the gear icon, click More….
  • In the Project Interpreters dialog box, click the plus sign +, click Add Local.
    • Enter ~/virtualenvs/<your virtualenv name>/bin/python in the path. If you followed the earlier post to setup a virtual environment for Python then enter ~/virtualenvs/api/bin/python.
    • Click OK.
  • Select 2.7.6 virtualenv at ~/virtualenvs/api, click the edit icon.
  • Check Associate this virtual environment with current project.
  • Click OK.
  • Click OK.
  • Click Apply, click OK.

Change the path to the interpreter on Windows.

خروجی فارسی (UTF-8) در پایتون

import codecs
import os
import sys

output_str = "تست خروجی فارسی"
if sys.stdout.encoding == 'UTF-8':
print(output_str)
else:
output_str += os.linesep
if sys.version_info[0] >= 3:
sys.stdout.buffer.write(bytes(output_str.encode('utf-8')))
else:
codecs.getwriter('utf-8')(sys.stdout).write(output_str)