So I tried to install flask package inside virtualenv.
$ virtualenv env
Using base prefix '/usr'
New python executable in /home/egor/Documents/python/projects/flask/env/bin/python3
Also creating executable in /home/egor/Documents/python/projects/flask/env/bin/python
Installing setuptools, pip, wheel...done.
$ . ./env/bin/activate
(env) $ sudo pip3 install flask
After this I tried to import flask package in python and got ImportError exception. (env) $ pip3 freeze gave me nothing.
Then I've discovered package in /usr/local/lib/python3.5/dist-packages directory.
So basically pip3 inside vurtualenv install packages in the wrong place.
How can I solve this problem? Is it because of Using base prefix '/usr' line?
I believe that pip doesn't need root privilege (especially in a virtual env). Try pip3 install flask without sudo.
Related
I have on my Fedora 20 additionally to 2.7 a python3.6 version installed.
When I run a script with the 3.6 version it's missing the requests module.
When I try to install it with the pip command it says it's already there.
So, how can I install this module in python3.6?
Any hints?
Thanks
Check if pip36 or more likely pip3 is a function you can run. Often times the pip command corresponds to the first installed python version, so if you install one later it gets the suffix according to its version. If that is the case then you'll want to do pip36 (pip3) install moduleXYZ.
Quick and dirty answer is
For python2,x install any package using pip install requests
For python 3.x install any package using pip3 install requests
If you get error during pip3 please run sudo dnf install python3-pip
But the right way is to do it using Virtual Environment in fedona
For py3.4+
$ python3.5 -m venv env # create the virtualenv
$ . env/bin/activate # activate it
(env)$ python -m pip install requests # install a package with pip
For py2.x, 3.x
$ dnf install python-virtualenv # install the necessary tool
$ virtualenv --python /usr/bin/python2.7 env # create the virtualenv
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in env/bin/python2.7
Also creating executable in env/bin/python
Installing setuptools, pip...done.
$ . env/bin/activate # activate it
(env)$ python -m pip install requests # install a package with pip
Refrence
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.
I have installed virtualenv
sudo pip3 install virtualenv
Then created a new virtualenv
virtualenv --python=/usr/bin/python3.5 venv
It returned
Running virtualenv with interpreter /usr/bin/python3.5
Using base prefix '/usr'
New python executable in /home/alexandra/Documents/online-store/venv/bin/python3.5
Also creating executable in /home/alexandra/Documents/online-store/venv/bin/python
Installing setuptools, pip, wheel...done.
Activated it
source venv/bin/activate
Then installed Django
sudo pip3 install django
It installed there (that is what sudo pip3 install django --upgrade returned)
/usr/local/lib/python3.4/dist-packages
Maybe that's the problem? Because it installed in python3.4 and not python3.5. But how to install Django in python3.5?
In file manage.py there is a path to python3.5 in this virtualenv.
Then I run
python manage.py runserver
It returns an error
Traceback (most recent call last):
File "manage.py", line 8, in <module>
from django.core.management import execute_from_command_line
ImportError: No module named 'django'
Can anyone help me?
When using pip to install packages inside the virtual env, do not sudo. It makes packages be installed globally. Simply remove sudo from beginning of the command and it should install it in the venv you are currently working on.
You installed django into a system python 3.4.
When you ran install command first time without sudo, did it complain about permissions? That should have been your clue that it's not the right pip. My guess is pip3 only exists in system python and not your virtualenv. You can use which to find out, but this will work in any case:
venv/bin/pip install django
Don't do sudo and just use pip for installing all the packages. You have already installed python3 in your virtualenv, so there is no need of using pip3.
Just do e.g. pip install django. or for other packages pip install <package_name>
I'm having trouble with Python virtualenv on OSX. After creating a virtualenv and doing a pip freeze it says it's got a long list of things installed, which are actually the things I've got installed on my main pip installation (outside of the virtualenv):
kramer65$ virtualenv venv
New python executable in venv/bin/python
Installing setuptools, pip, wheel...done.
kramer65$ source venv/bin/activate
(venv)kramer65$ which pip
/Users/kramer65/repos/venv/bin/pip
(venv)kramer65$ pip freeze
apns==2.0.1
APScheduler==3.0.4
argh==0.26.1
Babel==1.3
beautifulsoup4==4.4.1
etc.
etc.
I've got virtualenv version 13.1.2, which I think is the latest.
So to be sure I tried calling pip with a direct link, but that gives the same result:
(venv)kramer65$ ./venv/bin/pip freeze
apns==2.0.1
APScheduler==3.0.4
etc.
etc.
or even by calling pip with the virtualenv python:
(venv)kramer65$ ./venv/bin/python venv/bin/pip freeze
apns==2.0.1
APScheduler==3.0.4
etc.
etc.
I also uninstalled and reinstalled virtualenv, but with the same result. Does anybody know why I can't seem to be able to call the Python of the installed virtualenv? All tips are welcome!
[EDIT]
As per the suggestion of #sushant below I tried using --no-site-packages:
kramer65$ virtualenv --no-site-packages venv
New python executable in venv/bin/python
Installing setuptools, pip, wheel...done.
kramer65$ source venv/bin/activate
(venv)kramer65$ pip freeze
apns==2.0.1
APScheduler==3.0.4
argh==0.26.1
Babel==1.3
beautifulsoup4==4.4.1
etc.
etc.
(venv)kramer65$ which pip
/Users/kramer65/repos/venv/bin/pip
The problem is that your virtualenv installation is include main site-packages too.
virtualenv will not include site-packages if you invoke it like so:
virtualenv --no-site-packages venv
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