Module not found in python after installing in terminal - python

This question has been asked a few times, but the remedy appears to complicated enough that I'm still searching for a user specific solution. I recently re-installed anaconda; now, after entering
"pip install splinter"
in the Terminal on my Mac I get the response:
"Requirement already satisfied: splinter in /usr/local/lib/python2.7/site-packages
Requirement already satisfied: selenium>=2.53.6 in /usr/local/lib/python2.7/site-packages (from splinter)"
But, I get the following error in python (Anaconda) after entering import splinter
Traceback (most recent call last):
File "", line 1, in
import splinter
ImportError: No module named splinter"
When I enter which python in the terminal, this is the output: "/usr/local/bin/python"
I am editing the question here to add the solution: ~/anaconda2/bin/pip install splinter

1) Try uninstalling and the re install it:
pip uninstall splinter
2) Also manually delete splinter from "site-packages".
3)Also try this if problem still persists:
$ easy_install -m PACKAGE_name

those are two different pythons. you are using the pip from your default python, but trying to import the package from anaconda.
use
$ dirname `which python`
to see where the anaconda's python executable is, then see that folder for pip. now use this pip to install the package

I had the same issue, I uninstalled and reinstalled splinter many times but that didn't work. Then I typed source activate (name of my conda environment) and then did pip install splinter. It worked for me.

Related

Why is selenium not working even after I've installed it in Python?

I have both python 3.7 and 3.8. I've tried installing and uninstalling selenium multiples times, using a different command line in the terminal each time. Some things I've tried are
pip install selenium
sudo pip install selenium
sudo pip3 install selenium
sudo -H pip3 install -U selenium
I have even downloaded selenium-3.141.0.tar.gz from the pypi website, and run the set up file.
I consistently get the following message:
Requirement already satisfied: selenium in ./opt/anaconda3/lib/python3.7/site-packages (3.141.0) Requirement already satisfied: urllib3 in ./opt/anaconda3/lib/python3.7/site-packages (from selenium) (1.25.9)
However, when I try from selenium import webdriver in python, I get the following error message:
Traceback (most recent call last): File "<pyshell#2>", line 1, in <module>from selenium import webdriver ModuleNotFoundError: No module named 'selenium'
Why is python telling me that it is not installed but my terminal is telling me that it is already installed?
Another thing you should check: Virtual Environment Compatibilities
If you have a virtual environment for your project, you may have an issue where the package is not part of the dependencies defined in the venv if the venv was made before the selenium installation OR the project does not use the Python venv version. So you can rectify by
Go to your bash terminal and activate the virtual environment
$source venv\Scripts\activate #or can be
$source venv\bin\activate
Install selenium in the virtual environment with any of those commands depending on your version of Python.
Also make sure that in your editor, the settings are such that the venv is being used.
Try running python3 -m pip install selenium in the terminal
Check the Instructions for Windows users in the Selenium installation instructions.
It perfectly works, you just need to find your python path and it is generally something like this: C:\Users\"yourname"\AppData\Local\Programs\Python

pip install error - ModuleNotFoundError when package already installed (Requirement already satisfied)

I'm trying to get started with BeautifulSoup but I'm having trouble installing and importing bs4. I type pip install beautifulsoup4 into the command prompt, and receive these two messages:
Requirement already satisfied: beautifulsoup4 in c:\users\jzhen\appdata\local\programs\python\python38-32\lib\site-packages (4.8.2)
Requirement already satisfied: soupsieve>=1.2 in c:\users\jzhen\appdata\local\programs\python\python38-32\lib\site-packages (from beautifulsoup4) (1.9.5)
However, when I run a program with just the single line
import bs4
from bs4 import BeautifulSoup
I get the error
File "c:/Users/jzhen/OneDrive/Desktop/PriceUpdate.py", line 1, in <module>
import bs4ModuleNotFoundError: No module named 'bs4'
ModuleNotFoundError: No module named 'bs4'
If you have multiple Python versions installed in your system maybe import bs4 returned an No module named 'bs4' error because you haven't installed beautifulsoup4 for the currently running Python interpreter. If you use python3 -m pip install instead of pip install then you know pip will be using and installing for your default Python 3.x interpreter.
python3 -m pip install beautifulsoup4
If the currently running Python interpreter is Python 2.x the alternative to the above command is:
python -m pip install beautifulsoup4
If the Python program is running in an IDE, then maybe your project is not configured to find Python packages that were installed globally by pip: https://stackoverflow.com/a/59422188
One solution, without virtual environment: I have 2 versions, i.e. python3.6 and python3.7
To fix these difficulties I also met with this kind of "site-package" , and because I have no "sudo" right on my windows 7 PC , this works for me : two installation "declaratives" as followed:
C:/Applications/Python/Python36/Scripts/pip3.6.exe install bs4
C:/Applications/Python/Python36/Scripts/pip3.6.exe install beautifulsoup4
C:/Applications/Python/Python37/Scripts/pip3.7.exe install bs4
C:/Applications/Python/Python37/Scripts/pip3.7.exe install beautifulsoup4
Are you working on any virtual environment? If yes then install bs4 separately in that environment using terminal. If you are using virtual environment then possibly its is not using global packages available so you'll have to install in activated virtual environment.

Module installed on Conda, but gives error on importing in Spyder (Python IDE)

I recently installed pybedtools in my Conda environment, using the command they mentioned -
conda install -c bioconda pybedtools
But then when I activated spyder in this environment, and tried to run import pybedtools it gave me the error-
Modulenotfounderror: no module named 'pybedtools'
I went back and tried to install using the module using pip too (pip install pybedtools) but it said that I already had it -
Requirement already satisfied: pybedtools in /anaconda3/envs/env1/lib/python3.5/site-packages
Requirement already satisfied: six in ./anaconda3/envs/env1/lib/python3.5/site-packages (from pybedtools)
So, I am unable to understand how it is that the module is installed yet Spyder does not allow me to import it. I have never faced this issue with Anaconda before. Any help would be great!
Here is how I was able to solve the issue -
activate the root environment. This can be done by activate root in Windows and source activate root in Ubuntu/Mac
install the said package here. This can be done using the same command that you used to install the package in your previous environment
Go back to your original environment. The problem will now be resolved.
I would love to know, though, why this method works!

Python import fails Openpyxl

I know many questions speak about this problem, but i tried a lot and didn't fin any solution to my "very classical" issue : Python import fails altough package installed:
MacBook-Pro-de-Stephanie:scripts user$ sudo -H pip install openpyxl
Collecting openpyxl
Requirement already satisfied (use --upgrade to upgrade): jdcal in /usr/local/lib/python2.7/site-packages (from openpyxl)
Requirement already satisfied (use --upgrade to upgrade): et-xmlfile in /usr/local/lib/python2.7/site-packages (from openpyxl)
Installing collected packages: openpyxl
Successfully installed openpyxl-2.3.5
Package installed right ?
MacBook-Pro-de-Stephanie:scripts user$ python interactionsXLSX2CSV.py
Traceback (most recent call last):
File "interactionsXLSX2CSV.py", line 5, in <module>
from openpyxl import load_workbook
ImportError: No module named openpyxl
Fails right ?
MacBook-Pro-de-Stephanie:scripts user$ echo $PYTHONPATH
/usr/local/lib/python2.7/:
Path seems ok, no ?
I set permissions with:
sudo chmod -R ugo+rX ./lib/python2.7/site-packages/
What can i try else ?
Thank you very much
Here was the solution for me (linked to Mac OS clearly) : Can't load Python modules installed via pip from site-packages directory
/usr/bin/python is the executable for the python that comes with OS
X. /usr/local/lib is a location for user-installed programs only,
possibly from Python.org or Homebrew. So you're mixing different
Python installs, and changing the python path is only a partial
workaround for different packages being installed for different
installations.
In order to make sure you use the pip associated with a particular
python, you can run python -m pip install <pkg>, or go look at what
the pip on your path is, or is symlinked to.
I am not getting that error. Just now i installed. All i am getting is
" /usr/local/lib/python2.7/dist-packages/openpyxl/xml/init.py:15: UserWarning: The installed version of lxml is too old to be used with openpyxl
warnings.warn("The installed version of lxml is too old to be used with openpyxl")"
Once try by using below command.
sudo apt-get install python-openpyxl

Import Error: No module named requests

I know there are many posts on this, and I've tried using the solutions provided, but to no avail. I tried pip install requests and pip install requests --upgrade:
pip install requests --upgrade
You are using pip version 7.1.0, however version 7.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Requirement already up-to-date: requests in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
I then tried running pip install --upgrade pip, yet when I run my file I still get
Import Error: No module named requests
I am able to use requests in PyCharm, so I don't know what's causing this. Can someone please help?
You installed requests into a different Python installation. The /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages is the site-packages directory for the Mac OS X /usr/bin/python installation.
PyCharm is not currently configured to use that Python installation; check what Python is being used either by looking at your PyCharm settings, or by asking Python directly with:
import sys
print(sys.executable)
Note that PyCharm can handle package installations for you as well; rather than use the command line pip consider using PyCharm, as it'll use the currently configured Python installation in that case.
install package name "request" from pychram package setting. then it will be work fine.
If you are having this issue in Pycharm and you have configured your Pycharm to create projects in virtual environments, then you can use the Terminal in Pycharm to run the
pip3 install requests
to resolve this issue. This is by design to ensure you control dependencies.

Categories