I have python 3.x, and was told to install Pillow for image manipulation. After installing it with pip however, i'm unable to import PIL from the python interpreter. It just says ImportError: No module named 'PIL'. Running pip list in the command line shows that Pillow is indeed installed.
It ended up installing correctly after using easy_install instead of pip.
You might have used pip for a different python executable. To make sure that the correct pip command is used, run:
$ python3 -m pip install pillow
I don't really have the time or the means to create an entire virtual machine just for the purposes of testing this one problem.
virtualenv is not a virtual machine. All you need to create a virtualenv from scratch:
$ python3 -m pip install --user virtualenv # install package
$ python3 -m virtualenv venv # create virtualenv named 'venv'
Then to activate the created virtualenv on POSIX system:
$ source venv/bin/activate # activate on POSIX
Or on Windows:
C:\> venv\Scripts\activate
Now, python, pip commands refers to the virtualenv. To deactivate virtualenv, run:
$ deactivate
Related
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 need to find the python packages within my virtual environment.
When I run pip freeze I can see all the packages in the virtual environment.
However, when I cd ./venv/ and run tree Pillow (or manually search) I cannot find any installed package.
Any idea where they are stored?
Ask pip to tell you where it installed the project with the following command:
$ path/to/venv/bin/python -m pip show --files Pillow
from virtualenv do pip -V
It will be in : <virtual env root dir> + lib
example from my terminal
(vams_test) C:\VAMS\jiras\vams>pip -V
pip 19.2.3 from c:\vams\code\copy_v0.1\vams_test\lib\site-packages\pip (python 3.7)
I installed Python 3.7.1 using home-brew, and on the command line typing python returns the default python 2.7.10 and python3 gives the home-brew installed version. Then using
python3 -m pip install --user numpy scipy matplotlib
I installed the required packages.
Now what I understand is that to use the home-brew version python I have to always use python3and the required packages are installed inside python 3's lib folder.
I want to install virtual env correctly. I want to know what command should I use if I want it to be usable with python3?
You don't need to install virtual env because venv module is included in Python 3 standard library.
To create a virtualenv under .venv subdirectory of the current working directory:
python3 -m venv .venv
From my understanding you want to create python3 environments. First install virtualenv using pip.
pip install virtualenv
Then you can create a python3 environment like this:
virtualenv -p python3 env_name
I used VirtualEnv to create a python2 environment without system site packages like this:
virtualenv -p /usr/bin/python2.7 --no-site-packages ENV2.7
And I want to install packages in this environment.
However, I found that my python code is still trying to look for packages out of this environment.
For example, after activate this env, I used:
pip install matplotlib
And in my demo.py, there is
import matplotlib
But this raised an error, and can not find this package
However, when I use python in the terminal and enter the interactive python, import matplotlib dose not raise an error.
Then I started another terminal and tried to install this package out of the environment by pip3:
pip3 install matplotlib
It turned out that my demo.py just work well.
Any idea? Many Thanks!
It sounds like your virtualenv pip version may be using pip3 instead of pip2:
Make sure you are using the correct python version in your project that you mean to, and using the same version of pip in your virtualenv. (Note that you use pip above once, then you used pip3 outside your virtualenv.)
Check your pip version from inside the virtualenv:
workon (your env name)
which pip
pip -V
Output should look something like:
$ which pip
/home/yourname/.virtualenvs/testenv/bin/pip
$ pip -V
pip 9.0.1 from /home/yourname/.virtualenvs/testenv/local/lib/python2.7/site-packages (python 2.7)
It should tell you you're using pip inside your virtualenv, and the correct python version.
If that looks correct, install your packages.
pip install (whatever)
Check they are installed with pip freeze.
Run your project. :)
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