美文网首页
How to add to the pythonpath in

How to add to the pythonpath in

作者: 9682f4e55d71 | 来源:发表于2018-03-06 10:04 被阅读5次

Windows 7 Professional I Modified @mongoose_za's answer to make it easier to change the python version:

  1. [Right Click]Computer > Properties >Advanced System Settings > Environment Variables

  2. Click [New] under "System Variable"

  3. Variable Name: PY_HOME, Variable Value: C:\path\to\python\version

    enter image description here
  4. Click [OK]

  5. Locate the "Path" System variable and click [Edit]

  6. Add the following to the existing variable:
    %PY_HOME%;%PY_HOME%\Scripts;%PY_HOME%\Lib;%PY_HOME%\DLLs;%PY_HOME%\Lib\lib-tk;

    enter image description here
  7. 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

相关文章

网友评论

      本文标题:How to add to the pythonpath in

      本文链接:https://www.haomeiwen.com/subject/bsrlfftx.html