Adding modules has been very confusing on my laptop. Whenever I run the pip command, it will appear to be successful – for example:
> pip install selenium
Requirement already satisfied (use --upgrade to upgrade): selenium in /usr/local/lib/python2.7/dist-packages
However, when I try to use it in running python example.py, I get:
Traceback (most recent call last):
File "scriptattempt.py", line 2, in <module>
from selenium import webdriver
ImportError: No module named selenium
Where this happens with pretty much any modules I try to import. Not exactly sure why, I installed python 3 in the past, so I wasn't sure if maybe that's causing problems. I tried python3 example.py, but got the same error for packages in the line before.
I looked in at my site-packages file, at location: /usr/local/lib/python2.7/site-packages
but it's empty. Is this my problem? Is pip not unpacking in the correct location?
Related
I ran into some problems with some pip installations. I have found a way of installing that works, but I feel like it's wrong.
I installed pygame from the cmd prompt and got this message:
Defaulting to user installation because normal site-packages is not
writeable Requirement already satisfied: pygame in
c:\users\Somenewguy\appdata\roaming\python\python310\site-packages
(2.1.2)
But when I went to pycharm and started my project, I got this message:
Traceback (most recent call last):
File "C:\Users\Somenewguy\Python Projects\new\main.py", line 1, in <module>
import pygame
ModuleNotFoundError: No module named 'pygame'
I then did the pygame pip installation from the terminal in pycharm. But this time I installed it directly into the project folder, and that approach worked.
This is the only way I can import pygame into my projects which I think is weird.
Why do I have to install this package for each project?
If you use a virtual-environment, this is the expected behavior. If you don't want to install it every time, use the system environnement.
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.
UPDATE: Thank you to everyone who answered and commented. I understand now that I have 2 versions of python installed. My program was running from "Miniconda3/python.exe ". While bs4 was installed in "c:\python38\lib\site-packages". I understand this to be the cause of the problem. I removed Minicoda3 but VS code still tries to use it when I run a program. How can I fix this?
When I run the following code:
>>> from bs4 import BeautifulSoup
Error:
I get the error: "No module named 'bs4'.
After I install bs4, It says "Requirement already satisfied" yet I get the same error.
Im not sure what I'm doing wrong, please help. Error messages below.
PS C:\Users\Admin\Desktop\exAPP> pip install bs4
Collecting bs4
Requirement already satisfied: beautifulsoup4 in c:\python38\lib\site-packages (from bs4) (4.9.1)
Requirement already satisfied: soupsieve>1.2 in c:\python38\lib\site-packages (from beautifulsoup4->bs4) (2.0.1)
Using legacy setup.py install for bs4, since package 'wheel' is not installed.
Installing collected packages: bs4
Successfully installed bs4-0.0.1
PS C:\Users\Admin\Desktop\exAPP> & C:/Users/Admin/Miniconda3/python.exe c:/Users/Admin/Desktop/JNB.py
Traceback (most recent call last):
File "c:/Users/Admin/Desktop/JNB.py", line 2, in <module>
import BeautifulSoup
ModuleNotFoundError: No module named 'BeautifulSoup'
PS C:\Users\Admin\Desktop\exAPP> & C:/Users/Admin/Miniconda3/python.exe c:/Users/Admin/Desktop/JNB.py
Traceback (most recent call last):
File "c:/Users/Admin/Desktop/JNB.py", line 2, in <module>
from bs4 import BeautifulSoup
ModuleNotFoundError: No module named 'bs4'
PS C:\Users\Admin\Desktop\exAPP>
You are using miniconda, which might not be on your PATH correctly such that pip is actually part of a separate Python installation.
You could use conda install pip, or C:/Users/Admin/Miniconda3/python.exe -m pip install bs4
Okay so my problems are fixed an my program is running. Like I said in the update the first problem was due to having 2 versions of python installed. After I removed the unwanted version it was still set as the python interpreter path. I was trying to fix this by going into VS code settings but was having no luck. Fortunately I finally noticed there was a button on bottom left of the screen that allowed me to change the path easily. Thanks again to those who commented and answered.
I am very new to Python and have reviewed multiple questions here on problems getting packages/modules to import but can't seem to work out what I'm doing wrong. I'm simply trying to import packages and use them in the Spyder console, I'm used to working in R Studio so that's kind of my point of reference.
I run the below code and receive the following messages.
pip install Pillow
Requirement already satisfied: Pillow in c:\users\name\anaconda3\lib\site-packages (7.0.0)
Note: you may need to restart the kernel to use updated packages.
import Pillow
Traceback (most recent call last):
File "<ipython-input-7-f4cbff62aba7>", line 1, in <module>
import Pillow
ModuleNotFoundError: No module named 'Pillow'
I also seem to be getting different results when I run pip install from the console vs from the text editor portion. When I run it from the console, I get the above result about it already being installed. When I run it from the text editor portion, I get the following.
runcell(0, 'C:/Users/name/.spyder-py3/temp.py')
File "C:\Users\name\.spyder-py3\temp.py", line 1
pip install Pillow
^
SyntaxError: invalid syntax
scoured many examples but couldn't find anything steps that resolved my issue. Python can't seem to find any package I install via PIP. For example:
tims-MacBook-Pro:~ timlindsey$ pip install numpy
Requirement already satisfied (use --upgrade to upgrade): numpy in /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python
however when I then go into python and try to import numpy
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named numpy
It appears to happen no matter what package I try to bring in via pip. I'll spare the text dump but numpy is indeed there in
pip list
it seems to be looking at the same python install:
tims-MacBook-Pro:~ timlindsey$ which python
/usr/local/bin/python
tims-MacBook-Pro:~ timlindsey$ which pip
/usr/local/bin/pip
here is my .bash_profile:
export ANDROID_HOME=/usr/local/opt/android-sdk
export PATH="/usr/local/sbin:$PATH"
export PATH="/usr/local/bin:$PATH"
export PATH="Users/timlindsey/anaconda/bin:$PATH"
source ~/.nvm/nvm.sh
I don't know where to go from here, any ideas?