Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
435 views
in Technique[技术] by (71.8m points)

python - 如何在Windows中添加到PYTHONPATH,以便找到我的模块/软件包?(How to add to the PYTHONPATH in Windows, so it finds my modules/packages?)

I have a directory which hosts all of my Django apps ( C:\My_Projects ).

(我有一个目录,托管所有我的Django应用( C:\My_Projects )。)

I want to add this directory to my PYTHONPATH so I can call the apps directly.

(我想将此目录添加到我的PYTHONPATH以便直接调用应用程序。)

I tried adding C:\My_Projects\;

(我尝试添加C:\My_Projects\;)

to my Windows Path variable from the Windows GUI ( My Computer > Properties > Advanced System Settings > Environment Variables ).

(从Windows GUI( My Computer > Properties > Advanced System Settings > Environment Variables )添加到我的Windows Path变量。)

But it still doesn't read the coltrane module and generates this error:

(但是它仍然不读取coltrane模块并生成此错误:)

Error: No module named coltrane

(错误:没有名为coltrane的模块)

  ask by darren translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You know what has worked for me really well on windows.

(您知道在Windows上对我非常有效的方法。)

My Computer > Properties > Advanced System Settings > Environment Variables >

Just add the path as C:\Python27 (or wherever you installed python)

(只需将路径添加为C:\ Python27(或安装python的任何位置))

OR

(要么)

Then under system variables I create a new Variable called PythonPath .

(然后在系统变量下创建一个名为PythonPath的新变量。)

In this variable I have C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;C:\other-folders-on-the-path

(在这个变量中,我有C:\Python27\Lib;C:\Python27\DLLs;C:\Python27\Lib\lib-tk;C:\other-folders-on-the-path)

在此处输入图片说明

This is the best way that has worked for me which I hadn't found in any of the docs offered.

(这是对我有用的最好方法,我在提供的任何文档中都没有找到它。)

EDIT: For those who are not able to get it, Please add

(编辑:对于那些谁无法获得它,请添加)

C:\Python27;

(C:\ Python27;)

along with it.

(随之而来。)

Else it will never work .

(否则它将永远无法正常工作 。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...