Pip not working inside Virtual Env but works outside perfectly - python

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

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.

I had renamed the folder of virtual environment so that I was getting this error.
Then I renamed the venv folder name to the path mentioned in the error (That is the one which I had named while creating venv.) then tried to use pip and it worked.
Might be you have already solved your issue, but this is for the future visitors.

Related

Python virtual environment not installing packages in correct directory (python)

I have set up a virtual environment correctly have activated it and when I do "which python" it tells me the correct directory, but when I do pip install in the venv it installs the package in the default directory of the mac and not in my venv. I have tried using pycharm and installing packages with that, but it happens the same thing.
Edit:
Following I will do a walkthru of my steps, first I did python3 -m venv /path/to/new/virtual/environment, then I did source env/bin/activate, then I did which python and I got the intended directory, afterwards I did pip3 install numpy and I saw the installation process, then I did pip list and numpy was not there, I checked the directory manually and it still was not there. I retried all the same thing with pycharm with the same results.
Follow these steps in order -
In your current working directory :
python3 -m venv venv
source venv/bin/activate
(venv) pip3 install library_name
To check if libraries were properly installed or not :
(venv) pip3 freeze
and check if your installed libraries is displayed on the terminal screen or not.
To deactivate the virtual environment :
(venv) deactivate
This is due to permission issues
Run this command to change permission of your virtual environment folder
sudo chmod -R 777 venv
After activating your virtual environment
source venv/bin/activate
Then try to install Django by either Python3 or Python2
pip3 install django or pip install django
Then check the list of installed packages by either Python3 or Python2
pip3 list or pip list
NOTE: If you run sudo pip3 install django or pip install in virtual environment that is not writeable by default it will be installed outside of virtual environment
If you run pip3 install django or pip install in virtual environment that is not writtable by default it will be installed outside of virtual environment you will get OS Persmission Error
I have used pip3 and pip because you can install packages by either Python3 or Python2, thing to remember if you created virtual environment by Python3, use pip3 and if you created by using Python2 use pip.

I used pip3 to install virtualenv but I can't create venv and also I can't uninstall virtualenv

I'm using Linux Mint 20.2 with two directories / and /home.
I used the following command to install virtualenv:
>>> sudo pip3 install virtualenv
It worked fine and it installed in the following path:
>>> virtualenv --version
virtualenv 20.0.17 from /usr/lib/python3/dist-packages/virtualenv/__init__.py
But when I tried to create an environment I got the following error:
>>> python3 -m venv article
The virtual environment was not created successfully because ensurepip is not
available. On Debian/Ubuntu systems, you need to install the python3-venv
package using the following command.
apt install python3.8-venv
You may need to use sudo with that command. After installing the python3-venv
package, recreate your virtual environment.
Failing command: ['/home/username/article_tools/article/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']
When I tried to uninstall it to install it using [b]sudo apt install python3.8-venv[/b], I got the following error:
>>> sudo pip3 uninstall virtualenv
Found existing installation: virtualenv 20.0.17
Not uninstalling virtualenv at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'virtualenv'. No files were found to uninstall.
How can I fix it? By fix, I mean installing virtualenv in a way that I don't get such errors.
The fundamental problem here seems to be that you are mixing up two different packages.
Python 3 comes with a built-in virtual environment module venv which is however not installed by default on Debian-based platforms. Like the error message says, apt-get install -y python3-venv will install this package, which you can then use with python3 -m venv.
virtualenv is a separate third-party package which you invoke with the command virtualenv. It's not a bad alternative, but if you are only just learning, I would suggest you simply ignore it for the time being.

virtualenv is not picking python3 automatically from /usr/bin

I have installed new ubuntu 18.4 and while solving some other error while installing requirements through pip. I tried installing python-setuptools and python-dev instead of installing python3-setuptools and python3-dev which in turn installed python2.7 on my machine. Well the solution didn't work and I removed the packages as I don't want 2.7 on my machine and now when I run the following command:
sudo virtualenv venv
I get this message: The path python2 (from --python=python2) does not exist.
before installing python-dev and python-setup tools the above command worked fine.
I have tried replacing python symbolic link to python3.6 in /usr/bin.
by executing: ln -s /usr/bin/python3.6 /usr/bin/python although I am able to get python3.6 console every time run python like on fresh install of ubuntu but I can't creat virtual environment the same way.
Try yo run it with this specific python
/usr/bin/python3.6 -m pip install virtualenv
sudo /usr/bin/python3.6 -m virtualenv venv
and delete the python2.7 is probably a bad idea cause there is probably thing that using it on your machine, and also, consider reading about system envirmate varibles, as PATH for example that would solve you problem

bash: virtualenv: command not found "ON Linux"

I am using a form of Lubuntu called GalliumOS (optimized for Chromebooks). I installed pip using $ sudo apt-get install python-pip. I then used pip install --user virtualenv and pip install virtualenv, and then when I tried to subsequently use virtualenv venv I experienced the message bash: virtualenv: command not found.
Between the pip installs above, I used pip uninstall virtualenv to get back to square one. The error remained after a reinstall.
I read several other posts, but all of them seemed to deal with similar problems on MacOS. One that came close was installing python pip and virtualenv simultaneously. Since I had already installed pip, I didn't think that these quite applied to my issue. Why is pip install virtualenv not working this way on LUbuntu / GalliumOS?
Are you sure pip install is "failing"? To me, it sounds like the directory to which pip is installing modules on your machine is not in your PATH environment variable, so when virtualenv is installed, your computer has no idea where to find it when you just type in virtualenv.
Find where pip is installing things on your computer, and then check if the directory where the pyenv executable is placed is in your PATH variable (e.g. by doing echo $PATH to print your PATH variable). If it's not, you need to update your PATH variable by adding the following to your .bashrc or .bash_profile or etc.:
export PATH="PATH_TO_WHERE_PIP_PUTS_EXECUTABLES:$PATH"
What finally worked for me was this. I used
$ sudo apt-get install python-virtualenv.
I was then able to create a virtual environment using $ virtualenv venv.
I was seeking to avoid using $ sudo pip install virtualenv, because of admonitions in other posts to not do this, and agreed, because of experiences I'd had with subsequent difficulties when doing this.
pip install virtualenv
This command worked for me for. This problem that raised to me on Kali Linux.

Error With Installing Virtualenv With Pip and Homebrew

I am trying to get a nice clean Python environment setup on OSX 10.9. I've installed Python with Homebrew and set my PATH variables so...
> which python
/usr/local/bin/python
and
> which pip
/usr/local/bin/pip
so when I look at my /usr/local/bin :
pip -> ../Cellar/python/2.7.6/bin/pip
python -> ../Cellar/python/2.7.6/bin/python
then when I run:
> pip install virtualenv
I get permission errors on /usr/local/bin/virtualenv:
...
running install_scripts
Installing virtualenv script to /usr/local/bin
error: /usr/local/bin/virtualenv: Permission denied
I thought that by using Homebrew I could use pip and avoid using sudo to install virtualenv. Am I doing something wrong here?
Ok! I managed to fix this myself.
I deleted all the virtualenv related things from /usr/local/bin (they had been installed under root for some reason and this was causing my permission issues.).
Then I did a pip uninstall virtualenv to get rid of other instances of virtualenv, as there was still one in /usr/local/lib/python2.7/site-packages/
Then a simple pip install virtualenv and things work fine now!
Most likely HomeBrew does some magic so that running brew install allows writing to /usr/local/bin, but this privilege is not available to normal commands. This is a guess, I didn't investigate this further.
Install virtualenv with brew:
brew install pyenv-virtualenv
This command:
pip install virtualenv
runs pip from your first directory from $PATH environment variable, which is usually system wide, thus when you run in this way - you are trying to install it globall.
You should install you your environment in your $HOME directory:
virtualenv $HOME/myvirpython
and later:
$HOME/myvirpython/bin pip install something
Additionally you should read this:
https://docs.brew.sh/Homebrew-and-Python

Categories

Resources