简体   繁体   English

Django(w PyCharm)和PYTHON PATH问题

[英]Django (w PyCharm) & PYTHON PATH issue

I have purchased PyCharm and am trying to get things to work however I am encountering this issue.. 我已经购买了PyCharm,我正在努力让事情发挥作用,但是我遇到了这个问题。

Once I start a project everything works great... 一旦我开始一个项目,一切都很好......

Now if I want a standalone app.. let's say at /users/me/djangoApps I understand I have to add this directory to the python path.. I am trying to do so by creating a file sitecustomize.py at lib/python/2.6/site-packages/ 现在,如果我想要一个独立的应用程序..让我们说/ users / me / djangoApps我明白我必须将此目录添加到python路径..我试图通过在lib / python /创建文件sitecustomize.py来实现2.6 /站点包/

However once I create an app and try to import it I keep getting non excistance errors (yes I have reloaded the python interpreter in pycharm) 然而,一旦我创建一个应用程序并尝试导入它我一直得到非传染性错误(是的,我已经重新加载pycharm中的python解释器)

I reckon I am adding my locations to the python path in the wrong way.. Also I might not have my project location setup correctly (currently /users/me/djangoProjects) 我想我是以错误的方式将我的位置添加到python路径中。另外我可能没有正确设置我的项目位置(目前/ users / me / djangoProjects)

Thanks, 谢谢,

Novice django'r 新手django'r

在pycharm中打开设置“cmd”+“,”然后再到“Project Structure”,单击“Sources”以包含任何模块。

Don't add that file to your python site-packages, then your django project is gonna be included for all future projects down the road. 不要将该文件添加到您的python站点包中,然后您的django项目将被包含在未来的所有项目中。

If you wanna debug, within PyCharm, click the Run tab up top and choose Edit configurations. 如果您想在PyCharm中进行调试,请单击顶部的“运行”选项卡,然后选择“编辑配置”。 Choose the project you are working with and make sure you add the directory where your manage.py and settings.pr file are to the "Working Directory". 选择您正在使用的项目,并确保将manage.py和settings.pr文件所在的目录添加到“工作目录”中。 So I assume it might look something like this: 所以我认为它可能看起来像这样:

Working Directory: /users/me/djangoProjects/{Project Name} 工作目录:/ users / me / djangoProjects / {Project Name}

If there is something else that you need to add to the Python Path, you can add it it by going to File-Settings-Python Interpreter and then add a new path in the bottom window (but once again this will be used by any project you run in PyCharm 如果还有其他需要添加到Python Path的内容,可以通过转到File-Settings-Python Interpreter添加它,然后在底部窗口中添加一个新路径(但是这将再次被任何项目使用)你在PyCharm中运行

But if you are not debugging in PyCharm and just wanna run the app, I find it easier to run it from the command line. 但是如果你没有在PyCharm中调试并且只想运行应用程序,我发现从命令行运行它更容易。 I assume you are on Mac by your path, open the Terminal and go to the directory where your project is (same directory as the manage.py file) and type: 我假设您通过路径在Mac上,打开终端并转到项目所在的目录(与manage.py文件相同的目录)并键入:

python manange.py runserver python manange.py runserver

If you want to give it a specific port add it to the end 如果要为其指定特定端口,请将其添加到最后

python mange.py runserver 9000 python mange.py runserver 9000

This way you can edit your code in PyCharm and it will get reinterpreted when you save the file. 这样您就可以在PyCharm中编辑代码,并在保存文件时重新解释。 If you are debugging in PyCharm, you need to stop the debugger and run it again to pull in your changes 如果您在PyCharm中进行调试,则需要停止调试器并再次运行它以引入更改

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM