简体   繁体   English

在Pycharm中获取Django Project要求(已安装pip软件包)

[英]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

First attempt: 第一次尝试:

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控制台。

Second attempt: 第二次尝试:

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. workonvirtualenvwrapper命令,而不是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出现了问题,因此我借助与首次尝试相同的方法在帮助下解决了此问题。

  1. Disabled Django support (Settings -> Languages & Framework -> Django) 禁用Django支持(设置->语言和框架-> Django)
  2. Open the Python Console (Tools -> Python Console) 打开Python控制台(工具-> Python控制台)
  3. 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.

相关问题 Django pip freeze &gt; requirements.txt 没有在虚拟环境中安装确切的包 - Django pip freeze > requirements.txt not getting the exact packages installed in the virtual env 如果pip install-r requirements.txt被中断,是否会删除已经安装的软件包? - If pip install - r requirements.txt gets interrupted, will the already-installed packages get deleted? 使PyCharm在项目中使用Requirements.txt文件中更新的python包的最可靠方法是什么? - What is the surest way to get PyCharm to use updated python packages from requirements.txt file in a project? 找不到`pip install -r requirements.txt`安装的软件包 - Packages installed by `pip install -r requirements.txt` are not found Pycharm conda env没有显示通过pip安装的软件包 - Pycharm conda env not showing packages installed via pip Pycharm在windows上找不到pip安装的包或模块 - Pycharm cann't find the packages or modules installed with pip on windows 如何使用PyCharm 3.1.1中的项目要求文件升级软件包版本 - How to upgrade packages versions using project requirements file in PyCharm 3.1.1 如何在 venv 中安装软件包以显示在 PyCharm 项目中? - How can I get packages installed in venv to show up in PyCharm project? pip冻结&gt; requirements.pip在github安装的软件包上丢失了一些信息 - pip freeze > requirements.pip loses some info on github installed packages pycharm 中的 Pip 在 conda env 中安装包,而不是在项目内的活动 venv 中 - Pip in pycharm install packages in conda env and not in active venv inside project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM