Django (w PyCharm) & PYTHON 路径问题
我已经购买了 PyCharm 并且正在尝试让事情正常工作,但是我遇到了这个问题..
一旦我开始一个项目,一切都很好...
现在如果我想要一个独立的应用程序..让我们在 /users/me/djangoApps 说我我知道我必须将此目录添加到 python 路径中。我尝试通过在 lib/python/2.6/site-packages/ 创建文件 sitecustomize.py 来实现此目的,
但是一旦我创建了一个应用程序并尝试导入它,我就会保留出现不存在错误(是的,我已经在 pycharm 中重新加载了 python 解释器)
我认为我以错误的方式将我的位置添加到 python 路径中。此外,我可能没有正确设置我的项目位置(当前 /users/me/djangoProjects )
谢谢,
新手 django'r
I have purchased PyCharm and am trying to get things to work however I am encountering this issue..
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/
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)
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)
Thanks,
Novice django'r
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 pycharm 中打开设置“cmd”+“,”,然后在“项目结构”中单击“源”以包含任何模块。
In pycharm open the settings "cmd" + "," and then to "Project Structure" click on "Sources" to include any modules.
不要将该文件添加到您的 python 站点包中,那么您的 django 项目将包含在以后的所有项目中。
如果您想在 PyCharm 中进行调试,请单击顶部的“运行”选项卡,然后选择“编辑配置”。选择您正在使用的项目,并确保将 manage.py 和 settings.pr 文件所在的目录添加到“工作目录”中。所以我假设它可能看起来像这样:
工作目录:/users/me/djangoProjects/{Project Name}
如果您需要将其他内容添加到 Python 路径中,您可以通过转到文件设置来添加它-Python Interpreter,然后在底部窗口中添加一个新路径(但这将再次被您在 PyCharm 中运行的任何项目使用,
但是如果您不在 PyCharm 中调试而只想运行该应用程序,我发现运行它更容易从命令行,我假设您在Mac上,打开终端并转到项目所在的目录(与manage.py文件相同的目录)并输入:
python manange.py runserver
如果您想给出将其添加到末尾
python mange.py runserver 9000
这样您就可以在 PyCharm 中编辑代码,并且在保存文件时它将被重新解释。如果您在 PyCharm 中进行调试,则需要停止调试器并运行。再次拉入您的更改
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.
If you wanna debug, within PyCharm, click the Run tab up top and choose Edit configurations. 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". So I assume it might look something like this:
Working Directory: /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
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. 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:
python manange.py runserver
If you want to give it a specific port add it to the end
python mange.py runserver 9000
This way you can edit your code in PyCharm and it will get reinterpreted when you save the file. If you are debugging in PyCharm, you need to stop the debugger and run it again to pull in your changes