如何在windows上为pycharm配置django环境?
我是 django 开发的新手(我正在使用 MS 和 Oracle/Java 堆栈)。我现在知道正确准备开发环境是多么重要。我有一个网络服务器,其中有一些我要扩展的小型django项目,pycharm IDE(检查了可能性并选择了这个)在windows上。项目不在任何版本控制中,但我稍后会将其放入 git 中。
我的问题是 - 如何配置环境并将我的项目导入其中?是否可以将我的开发项目放入虚拟机并从Windows在pycharm中编辑它(尝试过但没有知道怎么做)还是我必须在 Windows 上安装 django?我有点不愿意将所有这些工作人员安装在我的工作站上,但这可能是必要的。是否可以仅为该项目安装 django 模块而不污染我的全局 python 环境?
这对于普通 django 开发人员来说可能是显而易见的,但我有点迷失。
I am new to django development (I was working with MS and Oracle/Java stack). I now how important it is to prepare your dev environment right. I have web server with some small django project I am going to expand, pycharm IDE (checked possibilities and chosen this one) on windows. Project is not in any version control but I am going to put it into git later.
My question is - how to configure environment and import my project into it? Is it possible to put my devproject into virtual machine and edit it in pycharm from windows (tried but didnt know how to do it) or do I have to install django on windows? I am a little reluctant to install all this staff on my workstation but it may be necessary. Is it possible to install django modules only for this project and not pollute my global python environment?
This may be obvious for regular django devs but I am little lost.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
自从我写下这个答案以来,PyCharm 极大地扩展了对虚拟环境的支持;现在您可以在启动项目时创建虚拟环境。
有关详细信息,请参阅 PyCharm 在线文档。
我在工作中在 Windows 上使用 PyCharm,这个过程对我来说很有效(因为 PyCharm 在项目创建阶段不支持虚拟环境)。您必须将 django 库放在您的开发计算机上才能使代码提示和方法签名发挥作用。
为此,您需要首先安装setuptools,然后安装pip 在你的系统 python 中。
对于新项目
首先创建您的虚拟环境,这将避免污染您的基本 Python 安装。
D:\>virtualenv --no-site-packages myenv
myenv\Scripts\python.exe 中的新 python 可执行文件
安装安装工具......完成。
安装 pip...................完成。
下一步,切换到这个环境:
D:\>myenv\Scripts\activate
(myenv)D:\>
将 django 安装到此环境中:
pip install django
,以及此项目可能需要的任何其他库。运行
PyCharm
和文件>新项目
为您的项目命名并从项目类型下拉列表中选择
Django 项目
在下一个屏幕上,单击 python 解释器右侧的按钮,浏览到您的虚拟环境,然后选择包含
python.exe
文件的目录.现在您的项目设置为仅使用 virtualenv python。完成开发后,您可以冻结安装并将其复制到您的测试环境中。
完成后,您只需删除目录
myenv
即可删除项目特定的库。Since I wrote this answer, PyCharm has greatly expanded their support for virtual environments; and now you can create virtual environments when starting projects.
For more information, see PyCharm online documentation.
I use PyCharm on Windows at work, and this process works for me (since PyCharm doesn't support virtual env in the project creation stage). You have to put the django libraries on your development machine for the code hinting and method signatures to work.
To do this, you need to first install setuptools and then install pip in your system python.
For New Projects
First create your virtual environment, this will avoid polluting your base python install.
D:\>virtualenv --no-site-packages myenv
New python executable in myenv\Scripts\python.exe
Installing setuptools................done.
Installing pip...................done.
Next, switch into this env:
D:\>myenv\Scripts\activate
(myenv)D:\>
Install django into this environment:
pip install django
, and any other libs you might need for this project.Run
PyCharm
andFile > New Project
Give your project a name and select
Django project
from the Project type drop downOn the next screen, click the button to the right of the python interpreter, and browse to your virtual environment, and select the directory with the
python.exe
file.Now your project is setup to only use the virtualenv python. Once you are done developing, you can freeze your install and replicate it on your testing environment.
Once you are done, you can simply delete the directory
myenv
to remove the project-specific libs.