I do not know why I cannot import selenium even after I pip install it.
Does anyone know how else I can troubleshoot it or how to fix this?
I am using Mac OS and python 3.7.4
python3
Python 3.7.4
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'selenium'
>>>
pip3 install selenium
Requirement already satisfied: selenium in /usr/local/lib/python3.7/site-packages
Requirement already satisfied: urllib3 in /usr/local/lib/python3.7/site-packages (from selenium)
UPDATE
I was kind of messing around and one of the things that I did helped make it work. I am not sure which of the items but if someone can explain it so I understand this in the future, that would be appreciated.
I did brew doctor which outputted the following
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!
Warning: A newer Command Line Tools release is available.
Update them from Software Update in System Preferences or
https://developer.apple.com/download/more/.
Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause brews that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
python
brew link --overwrite python
vi /usr/local/bin/pip
and changed /usr/local/opt/python/bin/python3.7 to /usr/local/opt/python/bin/python3 and it worked
I am guessing my issue is that I have two instances of python installed so it was downloading the selenium library to a difference python version (3.7) instead of 3 which is what I wanted.
Let me know if you think this was the issue or if you can clarify what you may think is the issue
try pip install, instead of pip3
Please check the pip version using command
pip --version
Mostly, pip is associated with python version 2.7 while pip3 is associated with python3
So, try -
pip3 install selenium
Since pip will install it for python2 while pip3 will install for python3 as you are using python3 in the question.
Related
I've been trying to import the psutil module from cygwin (as a Linux alternative for Windows 7). The installation worked, though.
When re-installed, it showed:
Requirement already satisfied: psutil in /usr/local/lib/python3.8/site-packages (0.1.3)
But when imported, it gave:
>>> import psutil
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.8/site-packages/psutil/__init__.py", line 61, in <module>
raise ImportError('no os specific module found')
ImportError: no os specific module found
I tried a couple of things:
Upgrading the pip and psutil itself, using these commands:
python3 -m pip install --upgrade pip
pip3 install --upgrade psutil
so the current version:
Requirement already satisfied: pip in /usr/local/lib/python3.8/site-packages (21.2.4)
Requirement already satisfied: psutil in /usr/local/lib/python3.8/site-packages (0.1.3)
Made sure that packages are installed only in the python 3.8.10 version (I have multiple versions of python installed, so I figured the inconsistency of versions may be causing the problem. But still, it didn't help).
Though, what I've done so far is just making sure I'd type an extra "3" after each python-related command.
I'm still new to cygwin and python, any help would be very much appreciated, thanks!
I may be wrong here, but I did some digging, and it looks like they have been trying add cygwin support for psutil since 2010, see github page for psutil issue #82. Looks like there is no support for now.
I've been trying for a couple of hours already. It seems IDLE can't find any third-party module. I am a Python beginner.
Here is some info about my system:
OSX version: 10.11.5
python version: Python 2.7, Python 3.4, Python 3.5
The initial installation using pip (among other methods) seems to work fine. When I repeat the installation, terminal responds with:
Requirement already satisfied (use --upgrade to upgrade): pyperclip in
./anaconda/lib/python3.4/site-packages
However, when I go to IDLE (Python 3.4) and try to import the module, IDLE responds with:
Traceback (most recent call last): File "", line 1, in
import pyperclip ImportError: No module named 'pyperclip'
I have read that it may have something to do with my PATH or some virtual environment. I’ll be frank, I’m not sure what to make of these as they seem beyond my current ability.
This inability to import modules is becoming an almost insurmountable roadblock to advancing with Python. If you can offer any ideas on what I can do or can ELI5 the solution, I am forever in your debt?
It seems you are using conda, but you are trying to install the pyperclip module with pip. Have you tried running conda install pyperclip?
As stated here:
Because Conda introduces a new packaging format, you cannot use pip and Conda interchangeably; pip cannot install the Conda package format. You can use the two tools side by side but they do not interoperate either.
I'm trying to install and use python for the first time, but I'm having problems using extern librairies.
/usr/bin/python /path/core/__init__.py
Traceback (most recent call last):
File "/Users/fabienlamarque/Downloads/RedditAPI/core/__init__.py", line 6, in <module>
import requests
ImportError: No module named requests
Source code :
import requests
r = requests.get(r'path/.json')
As I surfed around trying to find answers, I found some people telling me to use pip, I indeed used pip and pip3 (with python 2.7.5 and python 3.4.2), the answer is always:
$ pip install requests
Requirement already satisfied (use --upgrade to
upgrade): requests in /usr/local/lib/python2.7/site-packages
Cleaning up...
Which seems like a good thing, I forced the reinstallation of the module several times, but I always have the same problem. My IDE tells me "No module named 'requests'" though.
What did I miss?
Thanks
I see /usr/bin/python in there so it's a *nix variant.
you will probably find that which python and which pip point to different locations.
You can just download the source and use python setup.py install assuming that your user has write privilages to the puthon site-packages dir.
Virtualenv for virtualenvironments of even better, conda environments is soemthing I highly suggest learning early on to avoid these headaches on your leaning path.
Edit: Before you start deleting/modifying installs, please glance over StvnW's answer/summary to make sure you are applying the solution that is appropriate for you.
I've installed python 2.7.5 and pip [edit: mac OSX Mountain Lion.] I've run "pip install praw" in terminal. All good. When I run python and run "import praw" I get:
...$ python
Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import praw
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named praw
...same ImportError from a script.
when I install praw I get this:
$ pip install praw
Downloading/unpacking praw
Downloading praw-2.1.10.tar.gz (83kB): 83kB downloaded
Running setup.py egg_info for package praw
Requirement already satisfied (use --upgrade to upgrade): requests>=1.2.0 in
/usr/local/lib/python2.7/site-packages (from praw)
Requirement already satisfied (use --upgrade to upgrade): six in
/usr/local/lib/python2.7/site-packages (from praw)
Requirement already satisfied (use --upgrade to upgrade): update-checker>=0.6 in
/usr/local/lib/python2.7/site-packages (from praw)
Requirement already satisfied (use --upgrade to upgrade): setuptools in
/usr/local/lib/python2.7/site-packages/setuptools-1.1.6-py2.7.egg (from update-
checker>=0.6->praw)
Installing collected packages: praw
Running setup.py install for praw
Installing praw-multiprocess script to /usr/local/bin
Successfully installed praw
Cleaning up...
In python if I run help('modules') it isn't there.
Relatively new to python and I haven't been able to sort this out with google search. Any hints would be much appreciated.
Edit:
SitRep:
I've uninstalled 2.7.2, uninstalled praw, and uninstalled (homebrew) pip. I ran python 2.7.5 and it couldn't find the module (as you would suspect.) I then reinstalled pip with easy_install and now 2.7.5 is finding praw but giving this error:
$ python
Python 2.7.5 (v2.7.5:ab05e7dd2788, May 13 2013, 13:18:45)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import praw
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Python/2.7/site-packages/praw/__init__.py", line 43, in <module>
from update_checker import update_check
File "/Library/Python/2.7/site-packages/update_checker.py", line 11, in <module>
from pkg_resources import parse_version as V
ImportError: No module named pkg_resources
>>>
Thanks for the help so far, the spurious install was the root of problem 1.
The solution to the final problem can be found here:
No module named pkg_resources
I wish there were some way to summarize this for future readers, but I've done so many things that I no longer recall what addressed what. I basically uninstalled everything (python 2.7.2, 2.7.5, praw, pip,) reinstalled 2.7.5 from http://python.org/download/, reinstalled pip with easy_install (and sudo command) instead of homebrew, reinstalled praw with sudo command, and followed the directions for the subsequent module error in the link above. Hope that helps. :)
The OS X system versions of Python live in /System/Library/Frameworks/Python.Framework/<verson>, each of which links to /Library/Python/<version>/site-packages. Seems like you have installed another version of python and/or pip to /usr/local, but when you invoke python you are still getting the system version.
Try this:
$ /usr/local/bin/python
>>> import praw
I'd also recommend looking into tools like pyenv and virtualenv if you are going to do any amount of work with Python. Pyenv lets you easily manage and switch between multiple versions (including micro versions x.x.3, x.x.5, etc). Virtualenv lets you create isolated Python environments where you can pin down versions of site-packages specific to a particular project.
Edit (summarizing):
sudo easy_install pip will install pip under /System/Library/Python/<version>. Calling that pip will install packages to /Library/Python/<version>/site-packages
brew install python will install a second version of python — including pip — under /usr/local/. That pip will put packages in /usr/local/lib/python<version>/site-packages/`.
One version may not see packages installed to the other.
which python and which pip are helpful for troubleshooting.
Dean's final solution above results in user packages being installed to the system site-packages.
Despite Dean's choice to update the system Python, many would advocate instead using brew, pyenv, and virtualenv to isolate oneself from the system Python.
It's strange. I am suspecting you have another version of python2.7 on your mac os
If you are using a mac. Check the version of python on your shell's path using which python. Then make sure that the shebang line in the script you are trying to run uses the same version of python.
In my terminal I typed
which python and got the output /usr/local/bin/python
I went to the script I was trying to run and added the following to the first line
#!/usr/local/bin/python
Then I went back to my terminal. Checked that I was in the same directory as the script I wanted to run and typed
./my_script.py
If you don't see any output at this point make sure that you have execution permission enabled for your script by typing chmod +x my_script.py in ther terminal. Then try running the script again using ./my_script.py
I am used to the R functionality of installing packages and I am trying to do the same thing with ipython. Sometimes the following method works but then again sometimes it doesn't and I would like to finally find out why it only works half the time.
Normally to install a module (like the requests module for example) I would type the following after opening a fresh terminal:
$ sudo pip install requests
Password: *******
This would then be followed by a message indicating that the install was successful or that it has already been installed.
Requirement already satisfied (use --upgrade to upgrade):
requests in /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Cleaning up...
Which suggests that the code can be accessed. And indeed if I run python now from the terminal it shows a good response without any errors whatsoever.
$ python
ActivePython 2.7.2.5 (ActiveState Software Inc.) based on
Python 2.7.2 (default, Jun 24 2011, 12:20:15)
[GCC 4.2.1 (Apple Inc. build 5664)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>>
I now open PyLab through Alfred and it gives me an error.
Welcome to pylab, a matplotlib-based Python environment [backend: WXAgg].
For more information, type 'help(pylab)'.
In [1]: import requests
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/Users/vincentwarmerdam/<ipython-input-1-686486c241c8> in <module>()
----> 1 import requests
ImportError: No module named requests
I've read some help from another question on StackOverflow (here) which suggests that I install the module from ipython shell. This gives an even more baffling response:
In [2]: !pip install requests
Requirement already satisfied (use --upgrade to upgrade): requests in
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages
Cleaning up...
In [3]: import requests
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/Users/vincentwarmerdam/<ipython-input-3-686486c241c8> in <module>()
----> 1 import requests
ImportError: No module named requests
This seems very strange to me. Are there multiple versions of python installed on the system? How could I check this? Do I need to point ipython to the location of the installed code?
actually there is a much much much more elegant solution. when pip is installed then within python you can do things like this as well:
import pip
def install(package):
pip.main(['install', package])
install('requests')
which is easier. once logged into a virtualenv you can just make sure that you have what you need in the session you are in. easy.
edit
Another alternative would be to use the %%bash magic.
%%bash
pip install requests
edit2
If you want the standard output, one could even use the exclamation bang.
! pip install requests
edit3
From within ipython this is the safest installation method.
%pip install requests
This ensures that everything is installed in the virtualenv that your ipython is installed in.
Here's what I did that made it work; open up iypthon through the command line and type
import sys
sys.path
This shows a list of folders where other python modules are located. For me this was:
['',
'/Library/Frameworks/Python.framework/Versions/7.3/bin',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/pandas-0.10.0-py2.7-macosx-10.5-i386.egg',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/googlemaps-1.0.2-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/oauth-1.0.1-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/oauth2-1.5.211-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/httplib2-0.7.7-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/selenium-2.28.0-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/jellyfish-0.2.0-py2.7-macosx-10.5-i386.egg',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/python_yelp-0.1.1-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/pymongo-2.4.2_-py2.7-macosx-10.5-i386.egg',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/lucene_querybuilder-0.1.6-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/mechanize-0.2.5-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/html2text-3.200.3-py2.7.egg',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python27.zip',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/plat-darwin',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/plat-mac',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/plat-mac/lib-scriptpackages',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/lib-tk',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/lib-old',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/lib-dynload',
'/Users/vincentwarmerdam/Library/Python/2.7/lib/python/site-packages',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/PIL',
'/Library/Python/2.7/site-packages',
'/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/IPython/extensions]
With this information, I now knew where ipython looks for the modules that one can import. So I downloaded the requests library manually, added it to the same root directory such that the following directory exists:
/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/site-packages/requests
This folder contains the python modules that belong to requests. The only thing I now had to do was to make sure that ipython knows that this folder exists. Which was done by updating the sys.path.
req_link = '/Library/Frameworks/Python.framework/Versions/7.3/lib/python2.7/requests'
sys.path.append(req_link)
After this I no longer got the error.
import requests
Just works.
Also after restarting ipython, I found that ipython automatically updates the new path into the sys.path list.
If the new packages installed are imported on Terminal but not imported to ipython notebook then it is very likely that you have two versions of python installed on your library. Due to this there are separate site-packages directory from where packages are being imported on terminal and ipython notebook. To check if this is the case.
On terminal use:
import sys
sys.path
This will show where the python modules are located for python you using on terminal.
Now, in ipython notebook use:
import sys
sys.path
This will show where the python modules are located for python you using on terminal.
Now, if the two path are different you know you are using two different installations of python. To solve this problem, copy installed packages from site-packages directory of terminal python to site-packages directory of ipython.
I had this same problem when trying to install patool, but it turned out it was due to more than one interpreter installed, and when I ran it from ipython it worked.
This sorted me out running Spyder on Windows.
As the answer above, to find the directory:
import sys
sys.path
This site :
www.geeksforgeeks.org/how-to-install-pip-on-windows/
Directed me to this: https://bootstrap.pypa.io/get-pip.py
Use cmd to run that script from the directory of the version of Python you want to add modules to. Then just use pip to add the modules, again from the command line.
I didn't even bother adding any of it to my PATH, but you could do that.