I was trying to build Fisherfaces(https://github.com/bytefish/facerec) on my Mac(OS X 10.12.6), and I successfully built its dependencies including sklearn, numpy, scipy, matplotlib except Pillow.
So I tried :
pip3 install Pillow
at first I failed out of some network issue, so I tried again, and at last, I get this from terminal:
Installing collected packages: pillow
Successfully installed pillow-5.0.0
but then I tried on terminal:
TreaserdeMacBook-Pro:scripts treasersmac$ python3
Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'PIL'
and when I use python instead of python3, still get the same question.
Then I check the pip3 list:
TreaserdeMacBook-Pro:scripts treasersmac$ pip3 list
DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
cycler (0.10.0)
Django (2.0.1)
image (1.5.17)
matplotlib (2.0.0)
nose (1.3.7)
numpy (1.12.0)
Pillow (5.0.0)
pip (9.0.1)
pygal (1.7.0)
pyparsing (2.1.10)
python-dateutil (2.6.0)
pytz (2016.10)
requests (2.13.0)
scikit-learn (0.19.1)
setuptools (36.5.0)
six (1.10.0)
wheel (0.30.0)
seemed OK.
Then I checked path:
>>> import sys
>>> print(sys.path)
['', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python36.zip', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/lib-dynload', '/Users/treasersmac/Library/Python/3.6/lib/python/site-packages', '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages']
and PIL or Pillow was in:
/usr/local/lib/python3.6/site-packages
but:
TreaserdeMacBook-Pro:scripts treasersmac$ cd /usr/local/lib/python3.6/site-packages
TreaserdeMacBook-Pro:site-packages treasersmac$ ls
Django-2.0.1.dist-info numpy-1.13.3-py3.6.egg-info
PIL pip
Pillow-5.0.0.dist-info pip-9.0.1-py3.6.egg-info
__pycache__ pkg_resources
cv2.cpython-36m-darwin.so scikit_learn-0.19.1.dist-info
django setuptools
easy_install.py setuptools-36.5.0-py3.6.egg-info
homebrew-numpy-nose.pth sitecustomize.py
image sklearn
image-1.5.17.dist-info wheel
numpy wheel-0.30.0-py3.6.egg-info
I can import sklearn and sklearn can not be found in sys.path printed before.
I searched StackOverFlow but only to find that questions raised about PIL or Pillow were almost years ago, and not the same situation as mine.
(I think I used pip3 successfully installed Pillow..)
I'm new here, and urging for an answer...
Related
I can't get to successfully install the package 'mechanize' on a Raspberry Pi (so, ARM chip) with Debian Bullseye, python 3.9 in a virtualenv.
When I look in the virtualenv's sitepackages folder, indeed the mechanize package only has .dist-info file, but not a mechanize.py file or mechanize package folder. See below.
Question: Am I overlooking something?
Details (1): Installing mechanize with pip
(venvtest) pi#mango:~/MyProject/myproj $ pip --version
pip 20.3.4 from /home/pi/MyProject/myproj/venvtest/lib/python3.9/site-packages/pip (python 3.9)
(venvtest) pi#mango:~/MyProject/myproj $ pip install mechanize
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting mechanize
Using cached https://www.piwheels.org/simple/mechanize/mechanize-0.4.8-py2.py3-none-any.whl (5.1 kB)
Requirement already satisfied: html5lib>=0.999999999 in /home/pi/MyProject/myproj/venvtest/lib/python3.9/site-packages (from mechanize) (1.1)
Requirement already satisfied: webencodings in /home/pi/MyProject/myproj/venvtest/lib/python3.9/site-packages (from html5lib>=0.999999999->mechanize) (0.5.1)
Requirement already satisfied: six>=1.9 in /home/pi/MyProject/myproj/venvtest/lib/python3.9/site-packages (from html5lib>=0.999999999->mechanize) (1.16.0)
Installing collected packages: mechanize
Successfully installed mechanize-0.4.8
(venvtest) pi#mango:~/MyProject/myproj $ pip list
Package Version
------------- -------
html5lib 1.1
mechanize 0.4.8
pip 20.3.4
pkg-resources 0.0.0
setuptools 44.1.1
six 1.16.0
webencodings 0.5.1
wheel 0.34.2
Details (2): Package folder missing in sitelibs
(venvtest) pi#mango:~/MyProject/myproj/ $ ls venvtest/lib/python3.9/site-packages
easy_install.py pip-20.3.4.dist-info __pycache__ six.py wheel
html5lib pip-20.3.4.virtualenv setuptools _virtualenv.pth wheel-0.34.2.dist-info
html5lib-1.1.dist-info pkg_resources setuptools-44.1.1.dist-info _virtualenv.py wheel-0.34.2.virtualenv
mechanize-0.4.8.dist-info pkg_resources-0.0.0.dist-info setuptools-44.1.1.virtualenv webencodings
pip pkg_resources-0.0.0.virtualenv six-1.16.0.dist-info webencodings-0.5.1.dist-info
Details (3): As a consequence, importing mechanize doesn't work
(venvtest) pi#mango:~/MyProject/myproj $ python
Python 3.9.2 (default, Mar 12 2021, 04:06:34)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mechanize
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'mechanize'
>>> exit()
I've found this thread : https://github.community/t/python-modulenotfounderror-although-module-is-installed-aiohttp/15425 , does this help ?
It appears to be an issue with version 0.4.8. Installing version 0.4.7 works fine:
pip install mechanize==0.4.7
as can be seen:
(venvtest) pi#mango:~/MyProj/myproj $ python
Python 3.9.2 (default, Mar 12 2021, 04:06:34)
[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mechanize
>>> print(mechanize.__version__)
(0, 4, 7, None, None)
I've opened a ticket at the mechanize github repository: https://github.com/python-mechanize/mechanize/issues/76
I believe I'm following commonly perscribed means of installing a python package. First I activate the virtual environment:
[]$ source virt_env/bin/activate
Then I check to see that the python and pip versions and locations are correct:
(virt_env) []$ which python
~/virt_env/bin/python
(virt_env) []]$ which pip
~/virt_env/bin/pip
Now I attempt to install with pip and it succeeds
(virt_env) []$ pip install pandas
Collecting pandas
Using cached https://files.pythonhosted.org/packages/b7/e3/f52d484244105fa3d558ce8217a5190cd3d40536076bef66d92d01566325/pandas-0.23.4-cp27-cp27mu-manylinux1_x86_64.whl
Collecting numpy>=1.9.0 (from pandas)
Using cached https://files.pythonhosted.org/packages/9e/eb/c9eda9f4865d669e0bb37ce5c780e86c63daa54ca827b95a171429012d08/numpy-1.15.3-cp27-cp27mu-manylinux1_x86_64.whl
Requirement already satisfied: python-dateutil>=2.5.0 in ./virt_env/lib/python2.7/dist-packages (from pandas) (2.7.3)
Requirement already satisfied: pytz>=2011k in ./virt_env/lib/python2.7/dist-packages (from pandas) (2018.5)
Requirement already satisfied: six>=1.5 in ./virt_env/lib/python2.7/dist-packages (from python-dateutil>=2.5.0->pandas) (1.11.0)
Installing collected packages: numpy, pandas
Successfully installed numpy-1.15.3 pandas-0.23.4
However, when I try to import it in my python session, I cannot find pandas
(virt_env) []$ python
Python 2.7.14 (default, May 2 2018, 18:31:34)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pandas
Is this not the correct way to install? Looking in ./virt_env/lib/python2.7/dist-packages I see that pandas is no where to be found. Am I doing anything wrong?
I have tried doing python -m pip install pandas as well with no success.
I am on an Amazon ec2 instance running Amazon Linux.
Edit: python -m site returns the following:
sys.path = [
'',
'/home/myuser/virt_env/local/lib/python2.7/dist-packages',
'/home/myuser/virt_env/local/lib/python2.7/dist-packages',
'/home/myuser/virt_env/lib/python2.7/dist-packages',
'/home/myuser/virt_env/local/lib64/python2.7/site-packages',
'/home/myuser/virt_env/local/lib/python2.7/site-packages',
'/home/myuser/virt_env/lib64/python2.7',
'/home/myuser/virt_env/lib/python2.7',
'/home/myuser/virt_env/lib64/python2.7/site-packages',
'/home/myuser/virt_env/lib/python2.7/site-packages',
'/home/myuser/virt_env/lib64/python2.7/lib-dynload',
'/usr/lib64/python2.7',
'/usr/lib/python2.7',
]
USER_BASE: '/home/myuser/.local' (doesn't exist)
USER_SITE: '/home/muser/.local/lib/python2.7/site-packages' (doesn't exist)
ENABLE_USER_SITE: False
I am also able to install things if I use
pip install --install-option="--prefix=/home/myuser/virt_env" pandas
and then move the resulting files to the correct location.
I used pip3 to install tensorflow.. And after installation, I can find it in
/usr/local/lib/python3.6/site-packages
Besides, I use pip3 list and find it on the list:
vincent#ubuntu:/usr/local/lib/python3.6/site-packages/tensorflow$ pip3 list
backports.weakref (1.0rc1)
bleach (1.5.0)
html5lib (0.9999999)
Markdown (2.6.8)
numpy (1.13.1)
pip (9.0.1)
protobuf (3.3.0)
setuptools (28.8.0)
six (1.10.0)
tensorflow (1.2.1)
Werkzeug (0.12.2)
wheel (0.29.0)
But but I failed to import it in python3.6
vincent#ubuntu:/usr/local/lib/python3.6/site-packages/tensorflow$ python
Python 3.6.1 |Anaconda 4.4.0 (64-bit)| (default, May 11 2017, 13:09:58)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
>>>
What's wrong with it?
I ran it in Linux14.04(x64) in VMware
There may be multiple versions of python installed. You can do the following to ensure that tensorflow is installed for the version you are using -
python -mpip install tensorflow
Here I assume that you are using python prompt to run python. If you are using a different prompt just use that in place of python.
I'm still super new to coding! Trying to learn from online tutorials, but I seem to be stuck on the first step! I think I installed bs4, but it's not showing up in python3, is it installed in the wrong place?
robbie$ sudo -H pip install bs4
Requirement already satisfied: bs4 in /Library/Python/2.7/site-packages
Requirement already satisfied: beautifulsoup4 in /Library/Python/2.7/site-packages (from bs4)
Robbies-MBP:~ robbie$ python3
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import bs4
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'bs4'
Any help would be greatly appreciated :)
Requirement already satisfied: bs4 in /Library/Python/2.7/site-packages
Python 3.6.1 (v3.6.1:69c0db5050, Mar 21 2017, 01:21:04)
You have the module installed for Python 2.7, however you're using and trying to import it with Python 3.6.
You have to use pip3 like you use python3.
If you are using python 3 then you shoud use pip 3. In order to install it in ubuntu:
sudo apt install python3-pip
And then use the following command for installing the module bs4:
pip3 install bs4
go to the bottom left of your vs code and select python 3.9.1 64 bit (depending on the version of your python). it'll work.
it works for me
Just a quick note but a lot of times when this happens and you are running python3 and you used pip3 to install bs4 or another module but are running two different versions of python3 (eg 3.4 and 3.6). Sometimes just doing a normal update in a distro like CentOS installs a newer version of python, but not the corresponding pip.
Take for example here where a user is running python3.6 but all modules are installed only for python3.4 and there is no pip3.6 available.
http://realtechtalk.com/python_ModuleNotFoundError_No_module_named_bs4_even_though_you_have_the_module-2267-articles
I was having the same issue but managed to solve it with custom install script in the code. This tries to import and if it fails, automatically installs it
def safe_import(module):
try:
exec(f'import {module}')
globals()[module] = eval(module)
except ModuleNotFoundError as err:
import os
os.system(f'pip install {module}')
exec(f'import {module}')
globals()[module] = eval(module)
I am coming across a strange problem, I already installed python packages but it doesn't recognize them. please note that some packages are recognizable.
An example of importing a package
ActivePython 2.7.5.6 (ActiveState Software Inc.) based on
Python 2.7.5 (default, Sep 16 2013, 23:07:15)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named requests
Whenever I try to install it using Pip like
sudo pip install requests
I got this message whenever I try to install the same package.
Requirement already satisfied (use --upgrade to upgrade): requests in /usr/local/lib/python2.7/site-packages
What should I do to solve this problem ?
UPDATE_1
pip --version
pip 7.1.2 from /usr/local/lib/python2.7/site-packages
Find where pip installs your package and add the path to
export PYTHONPATH=<path>
#my path was /Library/Python/2.7/site-packages
in your .bashrc or .profile file.