0
votes

I'm trying to get, without success, the requirements.txt from the virtual environment I created in Pycharm for a Django Project. My Pycharm version is 2016.2, Django 1.10.3 and Python 3.5.1.

I want something like (example if I just had Django installed):

Django==1.10.3

First attempt:

Using Python Console - Didn't work because it automatically runs the Django shell instead. I've even tried changing the starting script in the Settings but the Django console is always opened instead of the Python one.

Second attempt:

Using the Terminal - Didn't work because it appears I don't have any virtual environment (doing lsvirtualenv gives an empty list)

2

2 Answers

1
votes

Maybe you don't have virtualenvwrapper installed? workon is a virtualenvwrapper command, not a virtualenv command. You can either install virtualenvwrapper and use workon or try using virtualenv's command like this:

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.

0
votes

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.

  1. Disabled Django support (Settings -> Languages & Framework -> Django)
  2. Open the Python Console (Tools -> Python Console)
  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.