Cannot import python package installed to virtualenv - python-3.x

I installed the python package Pillow to my virtualenv, but cannot import it. pip list | grep Pillow shows that it has been installed, and the virtualenv has been activated, but import Pillow still returns:
ImportError: No module named 'Pillow'
The virtualenv was created with
virtualenv -p python3.5 MainEnv
Pillow was installed with
pip install Pillow
Why can I not import the installed package?

I believe you pip install as Pillow, but import as PIL:
http://www.pythonforbeginners.com/gui/how-to-use-pillow

Related

Having issues to import imblearn python package on Jupyter notebook on Anaconda

I wanted to install imbalanced-learn using pip install imbalanced-learn. Then I have tried import
from imblearn.ensemble import EasyEnsembleClassifier
This import gave me the following error. I did try with uninstall imbalanced-learn and re-install imbalanced-learn, but it didn't help.
ImportError: cannot import name '_joblib_parallel_args' from 'sklearn.utils.fixes' (C:\Users\Jishan\anaconda3\envs\summerprojects\lib\site-packages\sklearn\utils\fixes.py)
I also tried
pip: pip install -U imbalanced-learn
anaconda: conda install -c glemaitre imbalanced-learn
They were not helpful as well. I was using Anaconda virtual environment. I appreciate your suggestions. Thanks!
you can try this :
conda install -c conda-forge imbalanced-learn to update documentation
sudo pip3 install imblearn to install imblearn
on command prompt : pip3 install imblearn
on anaconda !pip3 install imblearn

pip installs modules for python 2.7

I want to install a module with pip, in my case pydub.
However pip install pydub installs pydub in /home/<user>/.local/lib/python2.7/
So when I run my script
python3 myScript.py
it tells me
ModuleNotFoundError: No module named 'pydub'
How do I get pip to install pydub for 3.x rather than 2.7?
Use pip3 install xxx, or better yet, python3 -m pip install xxx. The problem here is that by default pip is aliased to python2's installation.

How to import in python 3?

I am self-learning Python and all the online courses use labs where all libraries are already imported. Whenever I try to import numpy or pandas or any other library I receive this message:
"Traceback (most recent call last):
File "<pyshell#6>", line 1, in
import numpy as np
ModuleNotFoundError: No module named 'numpy'"
What am I doing wrong?
import-error-no-module-named-numpy
ModuleNotFoundError is thrown when a module could not be found
Support for Python 3 was added in NumPy version 1.5.0
you do not install numpy Correctly
pip uninstall numpy
pip3 install numpy
I strongly recommend you use Virtualenv to install it numpy
pip install virtualenv
go to folder of your code use
virtualenv venv
//Windows
venv\Scripts\activate
//Linux
source venv/bin/activate
you can use conda to install numpy
download conda from here coda GUI installer
Best practice, use an environment rather than install in the base env
conda create -n my-env
conda activate my-env
If you want to install from conda-forge
conda config --env --add channels conda-forge
The actual install command
conda install numpy

ImportError: No module named PIL works for 3.7, but not 3.8

I have the Pillow module installed as seen on pip list. Which shows Pillow 7.2.0.
I have code which works on python 3.7.
from PIL import Image, ImageTk
However, when running the same on python 3.8 get the error message.
Exception has occurred: ModuleNotFoundError
No module named 'PIL'
I note there is supposed to be a working solution here:
stack link with potential solutions
2 solutions are:
import Image
uninstall Pillow and re-install
However, the above suggestions do not work.
How do i get Image and ImageTK working (on version 3.8) please ?
You could start a virtual environment venv or virtualenv with clean python3.8 and install modules there or try with:
python-3.8 -m pip install Pillow
or
python3.8 -m pip install Pillow
Edit:
In the end it worked with:
py -3.8 -m pip install Pillow
Hope this was useful ;)

pip install not working -- How to install/upgrade PyPi packages with pip v10 and above, using Python?

After upgrading my pip to version 10 using pip3 install --upgrade pip and above I cannot I want to install/upgrade PyPi packages using pip3 install PyPiPackageName as I get the following error:
from pip import main
ImportError: cannot import name main
I wonder how I can install PyPi packages using pip when I'm using new versions of pip? I've seen some people use pyhton3 to do this but doing python3 -m pip install --upgrade pip gave me the following error and I cannot upgrade pip to higher versions:
/usr/bin/python3: No module named pip
Before doing python3 -m pip install --upgrade pip I do python3 -m pip install -U pip and I get the following error:
/usr/bin/python3: No module named pip
So I'm confused on what I need to do to be able to upgrade or install PyPi packages.
In addition to executing the following:
curl https://bootstrap.pypa.io/get-pip.py | python3.6
I also had to make sure python3 is using Python 3.6 otherwise Python 3.5 is used (which does not come with pip by default). So I did the following and things work fine now:
ln -s /usr/bin/python3.6 /usr/local/bin/python3

Resources