0

I need to freeze my dependencies inside of virtualenv. As in virtualenv I have flask web application list of requirements should look like this:

Flask==0.10.1
Jinja2==2.7.3
Werkzeug==0.9.6
html5lib==0.999
itsdangerous==0.24
mote==0.0.3
ndg-httpsclient==0.3.2
pyasn1==0.1.7
requests==2.4.3
twython==3.1.2
urllib3==1.9.1
virtualenv==15.1.0
wheel==0.24.0
wsgiref==0.1.2

But when I try to freeze it by doing:

source venv/bin/activate
sudo sh -c 'sudo pip freeze > require.txt' # baceuse after simple  sudo pip freeze > requir.txt I am getting this error -bash: requir.txt: Permission denied

I am getting this list:

Cap1xxx==0.1.3
ExplorerHAT==0.4.2
Flask==0.10.1
Flask-Email==1.4.4
Flask-Login==0.4.1
Flask-Mail==0.9.1
Jinja2==2.7.3
MarkupSafe==0.23
MySQL-python==1.2.3
Pillow==2.6.1
RPi.GPIO==0.6.3
RTIMULib==7.2.1
Werkzeug==0.9.6
argparse==1.2.1
automationhat==0.0.4
blinker==1.3
blinkt==0.1.0
certifi==2018.1.18
chardet==3.0.4
colorama==0.3.2
dropbox==8.6.0
drumhat==0.0.5
envirophat==0.0.6
fourletterphat==0.0.2
gpiozero==1.4.0
html5lib==0.999
idna==2.6
itsdangerous==0.24
lxkeymap==0.1
mcpi==0.1.1
microdotphat==0.1.3
mote==0.0.3
motephat==0.0.2
ndg-httpsclient==0.3.2
numpy==1.8.2
phatbeat==0.0.2
pianohat==0.0.5
picamera==1.13
picraft==1.0
pifacecommon==4.2.1
pifacedigitalio==3.1.0
piglow==1.2.4
pigpio==1.35
pyOpenSSL==0.13.1
pyasn1==0.1.7
pygame==1.9.2a0
pygobject==3.14.0
pyinotify==0.9.4
pyserial==2.6
python-apt==0.9.3.12
rainbowhat==0.0.2
requests==2.18.4
scrollphat==0.0.7
scrollphathd==1.0.1
sense-emu==1.0
sense-hat==2.2.0
six==1.8.0
skywriter==0.0.7
smbus==1.1
sn3218==1.2.7
spidev==3.0
touchphat==0.0.1
twython==3.1.2
urllib3==1.22
virtualenv==15.1.0
wheel==0.24.0
wsgiref==0.1.2

which as you can see contains all installed packages and many of them are not connected to my flask web application like for instance numpy==1.8.2 or RPi.GPIO==0.6.3 despite the fact I am doing it inside of virtualenv..

So, is there a way to get list of dependencies which are bundled only with my flask app..?

Thanks!

davidism
  • 121,510
  • 29
  • 395
  • 339
John
  • 451
  • 6
  • 21

2 Answers2

0

As everyone said in comments just do

pip freeze > requirements.txt

sudo is not needed with virtualenv

Mike Tung
  • 4,735
  • 1
  • 17
  • 24
  • In this case I am getting an error: -bash: permission denied. After changing rights of the .txt file and doing this command the whole file is empty – John Jan 21 '18 at 18:31
  • 1
    You don’t need `sh -c` – Mike Tung Jan 21 '18 at 18:32
  • 1
    Yes, I got it. By 'this command' I meant your command: pip freeze > requirements.txt – John Jan 21 '18 at 18:33
  • Is pip owned by root? You may need to change perms – Mike Tung Jan 21 '18 at 18:36
  • Hm.. Actually I installed all packages by root.. Maybe – John Jan 21 '18 at 18:42
  • You can check this with `ls -l venv`. If you created it as root you should see something like `drwxrwxr-x 2 root root 4096 jan 19 15:33 bin` and so on. There is a way to change the owner of the entire virtualenv like this `sudo chown -R yourusername venv` Or better, if you the username john at your computer, you probably have a group name john as well so `sudo chown -R john.john venv` is even better (the second john is the group). – Arpad Horvath -- Слава Україні Jan 22 '18 at 10:58
-2

You can change the permisson the files as

 chmod 664 require.txt

and change the owner of the file to yours as

 chown myusername require.txt

(If you don't know your user name, you can ask with the command

 whoami

however usually it is in the command prompt.)