Virtualenv not detecting pip3 - python

I'm having problems running pip3 from virtualenv. If I run 'pip3 install django' in my active virtualenv, it will try to install it in my virtualenv, but fail because need privileges. The problem is, that when I use 'sudo pip3 install django', installs django globally. How can I avoid that?

SOLUTION
I solved it reinstalling virtualenv.
Thanks to Klaus D.
ALTERNATIVE SOLUTION
If everything else fail, you can still use pip explicitly:
myvirtualenv/bin/pip3 install django==1.7.1
and when you create your virtualenv do it without sudo, like:
virtualenv myvirtualenv --no-site-packages
Thanks to cesarkawakami from #python freenode irc.

Related

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.

What is the difference between pip install and sudo pip install?

I tried installing Flask and a few packages using sudo in a virtual environment, but on trying to import Flask, it'll throw up an ImportError. On installing the same packages with pip install though it works fine.
So what's the difference between these methods? I tried this on Ubuntu.
Also, where does pip install these packages? Looking through Stack Overflow I could only find questions that answer how to list packages installed by pip, but not where to find them (in context to the virtual environment)
pip install
Will run pip install as the current user
sudo pip install
Will run pip install with the security privileges of another user, root for example.
You normally need to use sudo to install a package on a system.
You may want to read linux-101-introduction-to-sudo

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

How to configure a virtual environment that doesn't require sudo?

In my Ubuntu 12.04 machine, the installation of pip requirements is asking me for sudo permission every time it attempts to install. How would I override this, as this is terrible for my working environment to install things globally instead of inside the venv?
Note: I did not setup the venv using sudo.
Have you activated your virtual environment? Run:
. bin/activate
in your shell. Then the local pip installation will take over the system one.
Thanks to #MartijnPieters, I found a workaround:
Running
~/.virtualenvs/myapp/bin/pip install -r requirements.txt
Instead of just
pip install -r requirements.txt
Make sure you use a recent version of virtualenv itself, the latest at the time of writing is 1.7.2. Old versions required the use of -E switch, to install into the virtual environment.

Why would pip install python packages outside of my current virtualenv?

I just installed virtualenv earlier today, and I've been trying to get django-nonrel to work using a virtual environment. After many hours of trying and failing to do so, I chatted with someone who suggested that the problem is with pip itself.
I create a virtual environment with virtualenv env_name. I enter it with:
source env_name/bin/activate
I then install something with pip. For example,
sudo pip install git+https://github.com/django-nonrel/django-nonrel;
I then perform a pip freeze, and the only output is:
wsgiref=0.1.2
Can anyone see why this might happen?
Thanks,
ParagonRG
Notes:
pip is version 1.1.
virtualenv is version 1..7.1.2
You forgot the git extension
$> mkvirtualenv test
(test)> pip install git+https://github.com/django-nonrel/django-nonrel.git
(test)> pip freeze
Django==1.3.1
wsgiref==0.1.2
By the way, you dont need to use sudo if you work with virtualenv. The idea is having your virtualen somewhere you have permission like ~/.virtualenvs/

Categories

Resources