Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pip not working inside Virtual Env but works outside perfectly

Hello Guys I am tying to follow the installation here https://github.com/systers/portal and trying to deploy the server inside a virtual environment on my machine. After lots of errors I decided to install a fresh copy of Ubuntu 16.04 and start After the installation here are the things that I have installed using the given commands

I checked my current python and python3 versions using python --version and python3--version respectively and they are Python 2.7.12 and Python 3.5.2 respectively.

Easy Install. $ sudo apt-get install python-setuptools python-dev build-essential  
pip. $ sudo easy_install pip
virtualenv. $ sudo pip install --upgrade virtualenv.
python3-dev tools.$sudo apt-get install python3-dev

Now after that I created a virtual env and activated it using the following commands

$ virtualenv venv1 --python=/usr/bin/python3
$ source venv/bin/activate

But now when I run the third command

$ pip install -r requirements/dev.txt

or even do

$pip --version

I get the error

bash: /media/rohan/New Volume/portal/venv1/bin/pip: "/media/rohan/New: bad interpreter: No such file or directory

Also in /venv1/bin the files pip,pip3 ,pip3.5 are present

I tried sudo easy_install pip thinking that it will install pip in the virtual environment but it installs to /usr/local/bin

Also I tried by creating a virtual env using the code

$virtualenv venv --python=/usr/bin/python

But that also doesnt work and this time also same error comes and in /venv/bin pip pip2 pip2.7 are present

PLEASE HELP

like image 654
Rohan Aggarwal Avatar asked Dec 13 '16 15:12

Rohan Aggarwal


People also ask

Why can’t I install any additional packages with pip install venv?

If you are in a production environment, you run pip install -r requirements.txt, and the extra packages in ‘requirements-dev.txt’ won’t be installed. There is an alternative to venv called pipenv, you can learn about it in this article: Virtual Environments in Python with Pipenv

Does a pip install always go into the root env?

If you only happen to have pip installed in your root env, and your root env is on your path, then yes a pip install will always (by coincidence) install into the root env.

Why is Pip $not working on my System?

Depending one which pip $ (which pip) points to, you may be installing into your system 's python environment. This is not optimal. And in the case where that IS what you intend, it is MUCH more rational to do that through your system's package manager like yum, apt, pacman, etc.

How do I install virtualenv in Python?

Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects. You can install virtualenv using pip. Unix/macOS python3 -m pip install --user virtualenv Windows py -m pip install --user virtualenv Creating a virtual environment¶


1 Answers

The problem appears to be that the path to your virtualenv has a space in it that isn't being escaped somewhere it should be.

Note the error you receive:

/media/rohan/New: bad interpreter: No such file or directory

So with that space in the path, it is trying to run a program that doesn't exist (/media/rohan/New) on a file that doesn't exist (Volume/portal/venv1/bin/pip).

Renaming New Volume to something without spaces like new_volume and then recreating a virtualenv should resolve this.

like image 97
chucksmash Avatar answered Oct 12 '22 13:10

chucksmash