[英]Get Django Project requirements (pip packages installed) in Pycharm
I'm trying to get, without success, the requirements.txt from the virtual environment I created in Pycharm for a Django Project. 我试图从我在Pycharm中为Django项目创建的虚拟环境中获取requirements.txt,但没有成功。 My Pycharm version is 2016.2, Django 1.10.3 and Python 3.5.1.
我的Pycharm版本是2016.2,Django 1.10.3和Python 3.5.1。
I want something like (example if I just had Django installed): 我想要类似的东西(例如,如果我刚刚安装了Django):
Django==1.10.3
Using Python Console - Didn't work because it automatically runs the Django shell instead. 使用Python控制台-无效,因为它会自动运行Django Shell。 I've even tried changing the starting script in the Settings but the Django console is always opened instead of the Python one.
我什至尝试在“设置”中更改启动脚本,但始终会打开Django控制台,而不是Python控制台。
Using the Terminal - Didn't work because it appears I don't have any virtual environment (doing lsvirtualenv
gives an empty list) 使用终端-
lsvirtualenv
,因为它似乎我没有任何虚拟环境(执行lsvirtualenv
会给出一个空列表)
Maybe you don't have virtualenvwrapper
installed? 也许您没有安装
virtualenvwrapper
? workon
is a virtualenvwrapper
command, not a virtualenv
command. workon
是virtualenvwrapper
命令,而不是virtualenv
命令。 You can either install virtualenvwrapper
and use workon
or try using virtualenv
's command like this: 您可以安装
virtualenvwrapper
并使用workon
也可以尝试使用virtualenv
的命令,如下所示:
source /path_to_your_virtualenv/bin/activate
If you do have virtualenvwrapper
, then you can create a virtual environment using mkvirtualenv -p <your_python> <your_env_name>
and use it inside PyCharm going to preferences
> Project interpreter
. 如果您有
virtualenvwrapper
,则可以使用mkvirtualenv -p <your_python> <your_env_name>
创建虚拟环境,并将其在PyCharm中使用,进入“ preferences
>“ Project interpreter
。
I've found that this is a common problem, already discussed here . 我发现这是一个常见问题,已经在这里进行了讨论。
As you can see from the discussion the values are easily obtained with pip freeze
for the virtualenv
is giving problems and so I solved this problem with the help of this anwer using the same approach as the First Attempt . 从讨论中可以看到,通过
pip freeze
很容易获得值,因为virtualenv
出现了问题,因此我借助与首次尝试相同的方法在此帮助下解决了此问题。
Do: 做:
from pip.operations import freeze x = freeze.freeze() for p in x: print (p)
You may copy the response content to requirements.txt
or change the script above to save the requirements directly to a file. 您可以将响应内容复制到
requirements.txt
或更改上面的脚本以将需求直接保存到文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.