Trying to install libraries in pypy - python

I knew that pypy is faster than CPython so I wanted to try it and it is actually way faster than CPython, however when I install libraries it shows the following:
PS C:\Users\DELL\Desktop\telegram\python -work some-> pip install pillow
Requirement already satisfied: pillow in c:\users\dell\appdata\roaming\python\python39\site-
packages (8.3.0)
but when I try to import the module (pillow):
Traceback (most recent call last):
File "c:/Users/DELL/Desktop/telegram/python -work some-/studying code 2.py", line 1, in
<module>
import pillow
ModuleNotFoundError: No module named 'pillow'
it is not there! please help!

pillow is an up-to-date fork of the now deprecated Python Image Library (PIL). you need to import PIL or from PIL import ... to use it.
Check out their documentation to learn more!

You must run pip with the version of Python you want to install the package for. In this case, you need pypy3 -m pip install pillow or something similar---run it with the same interpreter as the script you'll run next. In your pasted output, we see Requirement already satisfied: pillow in c:\users\dell\appdata\roaming\python\python39\site-packages which is the path for CPython 3.9, not PyPy.

Related

Says I don't have numpy, then it says it is already installed

I am having issues with the numpy library. I am trying to code a webcam using the opencv library, but I am getting this issue:
OpenCV bindings requires "numpy" package.
Install it via command:
pip install numpy
Traceback (most recent call last):
File "/home/pi/Documents/security-camera/take_picture.py", line 1, in <module>
import cv2
File "/home/pi/.local/lib/python3.9/site-packages/cv2/__init__.py", line 12, in <module>
import numpy.core.multiarray
ModuleNotFoundError: No module named 'numpy.core.multiarray'
When I try to install numpy using pip, I get this error:
pi#raspberrypi:~/Documents/security-camera $ python3 -m pip install numpy
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: numpy in /usr/lib/python3/dist-packages (1.19.5)
It says I already have the numpy library, even though when I run it says to install it. Does anyone know how to fix it?
I figured out how to solve this issue: I was getting an issue with numpy earlier and was trying to reinstall it, so I deleted the numpy folder in /usr/lib/python3/dist-packages, then I tried to install it again but it did not work. Then I got this issue. There are actually two numpy folders in /usr/lib/python3/dist-packages, so when I deleted the one with the python files in it, and imported numpy in the python program, it says numpy did not exist, but when I tried to reinstall numpy with pip, it said it already existed because it looked at the other folder. So what I had to do was delete the other folder in /usr/lib/python3/dist-packages, and then reinstalling numpy worked.

No module named 'psutil', although it is installed (MacOS)

When I run my code that includes psutil module I encounter the following error:
Traceback (most recent call last):
File "/Users/alek/Desktop/coloring/solver.py", line 4, in <module>
from psutil import cpu_count
ModuleNotFoundError: No module named 'psutil'
Although, when trying to install the module in terminal, I can see the following
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
Requirement already satisfied: psutil in /opt/homebrew/lib/python3.9/site-packages (5.9.1)
DEPRECATION: Configuring installation scheme with distutils config files is deprecated and will no longer work in the near future. If you are using a Homebrew or Linuxbrew Python, please see discussion at https://github.com/Homebrew/homebrew-core/issues/76621
WARNING: There was an error checking the latest version of pip.
How should I ensure that the module is in the right environment and can be used by my program?
Thanks in advance!
try to upgrade it
sudo pip install --upgrade psutil
try to run this command in python shell:
import site
site.getsitepackages()
actually, it is trying to search psutil module in one of the Xcode path.
see if you have psutil in this path:
/Applications/Xcode_13.4.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/lib/python3.8/site-packages
if not add the psutil module here and it should work.
it worked for me.

How can i install python modules that have spaces in between?

I wanted to run a script that would scan my network and that script uses a awesome library called who-is-on-my-wifi. I have installed the module to run the script but i get errors from the prompt saying that it cannot detect such a module in the system.
This is the script.
from who_is_on_my_wifi import *
WHO = who()
for i in range(0, len(WHO)):
print(WHO[i])
And this is the error that i get.
python scanner.py
Traceback (most recent call last):
File "scanner.py", line 1, in <module>
from who_is_on_my_wifi import *
ImportError: No module named who_is_on_my_wifi
This is the proof that i have installed the module
pip3 install 'who_is_on_my_wifi'
Requirement already satisfied: who_is_on_my_wifi in /home/harein/.local/lib/python3.8/site-packages (1.2.0)
Requirement already satisfied: getmac in /home/harein/.local/lib/python3.8/site-packages (from who_is_on_my_wifi) (0.8.2)
Requirement already satisfied: python-nmap in /home/harein/.local/lib/python3.8/site-packages (from who_is_on_my_wifi) (0.6.1)
Any suggestions on how i can avoid this can continue executing my script ?
EDIT
The script finally executed the way i want by changing the,
python scanner.py to python3 scanner.py
You guys were right, it was the way how i executed the script that generated this error and it was not a problem in the module apparently.
I would like to thank everyone who gave the support.<3
When trying to
import this_is_not_a_module
the error you get:
ImportError: No module named this_is_not_a_module
is the error raised by Python 2.
Python 3 would raise a different one:
ModuleNotFoundError: No module named 'this_is_not_a_module'
So, your actual problem is that your system tries to execute your script with some Python 2 version, while you installed your module for your Python 3.8 version.
sometimes you can't import modules because you have installed two python versions(or conda along with it). if you have, delete one of your python versions or activate conda and try importing your module, or just try:
pip uninstall who_is_on_my_wifi
pip install who_is_on_my_wifi
I usually tend to install modules per project and use virtualenv for it.
It kind of links respective versions of programs (like python interpreter, pip and so on) and takes care of PYTHONPATH and the way of installed dependencies.
$ pip3 install virtualenv
$ virtualenv whoisonwifi
$ source whoisonwifi/bin/activate
$ pip --version
pip 21.0.1 from
/mnt/devel/workonhome/whoisonwifi/lib/python3.7/site-packages/pip
(python 3.7)
$ pip install 'who_is_on_my_wifi'
from there your code (sort of) works for me.

cannot import module "cv2" in python on mac

I'm trying to use opencv-python. I imported with pip but it throws ModuleNotFound.
Joshua-Tews-MacBook-Pro:~ nathan$ pip install opencv-python
Requirement already satisfied: opencv-python in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (4.0.0.21)
Requirement already satisfied: numpy>=1.14.5 in /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages (from opencv-python) (1.16.2)
I import with this:
import cv2
I get this error:
Traceback (most recent call last):
File "/Users/nathan/Library/Mobile Documents/com~apple~CloudDocs/CEP/Y4/Capstone Project (Security Cameras System)/cep-ml-capstone/VideoProcessor.py", line 1, in <module>
import cv2
ModuleNotFoundError: No module named 'cv2'
I've look at the answers on this stackoverflow thread, none seem to help: Cannot import cv2 in python in OSX
Others have solutions I completely didn't recognise pertaining to other OS so I skipped those.
Okay I apparently I just had to run the script with Python 3.7 and it worked. I neglected to mention I was using Textmate.
To run scripts in Python 3.7 using Textmate, go to Preferences > Variables. If there isn't a variable named TM_PYTHON, create one then paste this in for the value: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3. Else, just change the value. Be sure to check the box next to the variable.

why i still can't use the NumPy module even the terminal says "requirement already satisfied"?

i was using
pip install numpy
to install NumPy on my Mac. Then the terminal says that
Requirement already satisfied: numpy in
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
I guess it means Numpy is already installed?
but when i wrote
from numpy import array
a=array([1,3],int)
the python shell says
Traceback (most recent call last):
File "/Users/bamford/Documents/python/untitled-3.py", line 1, in <module>
from numpy import array
builtins.ModuleNotFoundError: No module named 'numpy'
what is going on?
Per the comments, notice that your sys.path includes directories whose names imply they are associated with Python3.6:
[... '/Library/Frameworks/Python.framework/Versions/3.6/lib/pytho‌​n36.zip', ...]
Yet NumPy has been installed in your Python2.7 distribution:
Requirement already satisfied: numpy in
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
(my emphasis) So your Wing101 IDE is using Python3, and not finding NumPy because NumPy has not (yet) been installed in your Python3 distribution.
One solution would be to install NumPy for your Python3 distribution. (Another, might be to configure Wing101 to run Python2.7.) Often, the pip executable associated with Python3 is named pip3 (to distinguish it from a Python2 version called pip.) So you might try
pip3 install numpy
to install NumPy.
Moral of the story: Every pip is associated with a particular Python distribution. pip is a Python script. When run, it calls the Python executable associated with that distribution.
To install modules for a particular Python using pip, you need to call the pip script which is associated with the desired Python executable.
The message pip shows in your system
Requirement already satisfied: numpy in
/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
Here as you can note, numpy module is installed in python 2.7's directory.
You should install it in python 3.*'s directory. You can try that by
pip3 install numpy
pip3 installs python libraries in python 3.*directory
add sudo at the beginning of command to install it system wide.

Categories

Resources