Windows 7 Professional I Modified @mongoose_za's answer to make it easier to change the python version:
-
[Right Click]Computer > Properties >Advanced System Settings > Environment Variables
-
Click [New] under "System Variable"
-
Variable Name:
enter image description herePY_HOME
, Variable Value:C:\path\to\python\version
-
Click [OK]
-
Locate the "Path" System variable and click [Edit]
-
Add the following to the existing variable:
enter image description here
%PY_HOME%;%PY_HOME%\Scripts;%PY_HOME%\Lib;%PY_HOME%\DLLs;%PY_HOME%\Lib\lib-tk;
-
Click [OK] to close all of the windows.
As a final sanity check open a command prompt and enter python. You should see
>python [whatever version you are using]
If you need to switch between versions, you only need to modify the PY_HOME variable to point to the proper directory. This is bit easier to manage if you need multiple python versions installed.
当存在项目时,需要通过PYTHONPATH引入包,可以在添加该变量,
添加完成后,他会自动添加到python的 sys.path
>>> import sys
>>> print(sys.path)
['', 'G:\\cygwin_home\\user_name\\py_se\\Test_framework', 'D:\\server\\Python36-32\\python36.zip', 'D:\\server\\Python36-32\\DLLs', 'D:\\server\\Python36-32\\lib', 'D:\\server\\Python36-32', 'D:\\server\\Python36-32\\lib\\site-packages']
>>>
参考: https://stackoverflow.com/questions/3701646/how-to-add-to-the-pythonpath-in-windows-7
网友评论