How to add to the pythonpath in Windows?

2018-12-30 23:59发布

I have a directory which hosts all of my Django apps (C:\My_Projects). I want to add this directory to my pythonpath so I can call the apps directly.

I have tried adding C:\My_Projects\; to my Path variable from the Windows GUI (My Computer > Properties > Advanced System Settings > Environment Variables). But it still doesn't read the coltrane module and generates this error:

Error: No module named coltrane

17条回答
呛了眼睛熬了心
2楼-- · 2018-12-31 00:13

Maybe a little late, but this is how you add the path to the Windows Environment Variables.

  1. Go to the Environment Variables tab, you do this by pressing Windows key + Pausa inter.

  2. Go to Advanced System Settings.

  3. Click on Environment Variables.

  4. On the lower window search for the 'Path' value.

  5. Select it

  6. Click on Edit

  7. In the end of the line add your instalation folder and the route to 'Scripts' folder.

  8. Click ok, aceptar etc.

You're done, enter cmd and write python from any location of your drive, it should enter the Python program.

Example with my pc (I have Python34)

EXISTING_LINES;C:\Python34;C:\Python34\Scripts\

Hope it helps.

Greetings from Bogotá

查看更多
骚的不知所云
3楼-- · 2018-12-31 00:13

These answers are so bad. The installer has a secret option. Click the installer again, uninstall, then reinstall.

enter image description here

查看更多
笑指拈花
4楼-- · 2018-12-31 00:17

For anyone trying to achieve this with Python 3.3+, the Windows installer now includes an option to add python.exe to the system search path. Read more in the docs.

查看更多
长期被迫恋爱
5楼-- · 2018-12-31 00:20

The easier way to set the path in python is : click start> My Computer >Properties > Advanced System Settings > Environment Variables > second windows >

enter image description here

select Path > Edit > and then add ";C:\Python27\;C:\Python27\Scripts\"

link :http://docs.python-guide.org/en/latest/starting/install/win/

查看更多
素衣白纱
6楼-- · 2018-12-31 00:20

To augment PYTHONPATH, run regedit and navigate to KEY_LOCAL_MACHINE \SOFTWARE\Python\PythonCore and then select the folder for the python version you wish to use. Inside this is a folder labelled PythonPath, with one entry that specifies the paths where the default install stores modules. Right-click on PythonPath and choose to create a new key. You may want to name the key after the project whose module locations it will specify; this way, you can easily compartmentalize and track your path modifications.

thanks

查看更多
不再属于我。
7楼-- · 2018-12-31 00:22
import sys
sys.path.append("path/to/Modules")
print sys.path

This won't persist over reboots or get translated to other files. It is however great if you don't want to make a permanent modification to your system.

查看更多
登录 后发表回答