Unable to import praw module after install - python

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

Related

Selenium "No module named 'selenium' " even after pip3 install

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.

How should I remove multiple python versions due to which pip is pointing to some other version?

How should I remove multiple python versions due to which pip is pointing to some other version ?? due this even after successful installation the module is not getting imported??
Following is the error I was getting when I installed imutils successfully but still getting import error.
User-MacBook-Pro:~ user$ sudo pip install imutils
Collecting imutils
Installing collected packages: imutils
Successfully installed imutils-0.5.1
User-MacBook-Pro:~ user$ -H
-bash: -H: command not found
User-MacBook-Pro:~ user$ sudo -H pip install imutils
Requirement already satisfied: imutils in /usr/local/lib/python2.7/site-packages (0.5.1)
Installed imutils for Python2.7
and when I checked whether it is importing imutils library successfully or not then it displayed the following error message:
User-MacBook-Pro:~ user$ python
Python 2.7.14 (v2.7.14:84471935ed, Sep 16 2017, 12:01:12)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>import imutils
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named imutils
What is the problem here and how to fix it??
And following is my bin directory which has multiple python versions but I am not able to understand which one to remove??enter image description here
If there are multiple versions of Python on your computer, that's probably because you need different versions for the Software you have installed on your computer, or simply because you are working with different versions for different Projects.
Seeing that dependencies and the resolution thereof are a fairly intricate topic, it might be a good idea to use virtual environments to manage different versions, without interfering with an otherwise stable system python.
Once you wrap your head around virtual enviroments, they are not only convenient, but also elegant. Here's an introduction to get you started

import pyserial / serial not recognized by python, but dependencies already installed [Mac]

Dependencies for pyserial already installed, calling pyserial isn't recognized in python
Maxs-MacBook:~ grax$ sudo pip install pyserial
The directory '/Users/grax/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/Users/grax/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Requirement already satisfied: pyserial in /Library/Python/2.7/site-packages
Maxs-MacBook:~ grax$ python
Python 2.7.15 (default, May 2 2018, 00:53:27)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.29.1] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import pyserial
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Import Error: No module named pyserial
What should I do?
The python module is called serial even though you call pip pyserial. Confusing, yes.
import serial
The other issue may be that the instance of python you're using isn't the same as the one pip is installing for.
See where pip installed the module:
$ pip show pyserial
Name: pyserial
Version: 3.4
Summary: Python Serial Port Extension
Home-page: https://github.com/pyserial/pyserial
Author: Chris Liechti
Author-email: cliechti#gmx.net
License: BSD
Location: /Library/Python/2.7/site-packages
Because your Location is /Library/Python2.7... pip appears to be installing in the system directory.
However, the version of python you're using (Python 2.7.15) is not the one shipped with MacOSX, so it's probably looking for the python modules somewhere else.
$ python
>>> import sys
>>> print sys.path
The version of pip is most likely not installing there. (pip is not native to MacOS, so it may be using /usr/local/bin/python and /usr/local/lib/python2.7/site-packages.
You can force pip to install somewhere else using --target option:
$ sudo pip install --target /usr/local/lib/python2.7/site-packages pyserial
Which will put the serial module in the location your python is looking.

Module import error in virtualenv but pip list --local shows it

I'm wondering about the following importError which I can't get ride off. I have a local virtualenv (venv) in which I've installed multiple modules:
(venv) stam#stam:~$ pip list --local
cryptography (1.5.2)
cvxopt (1.1.9)
cycler (0.10.0)
Cython (0.25.1)
matplotlib (1.5.3)
more-itertools (2.2)
ndg-httpsclient (0.4.2)
numpy (1.11.2)
pandas (0.19.0)
paramiko (1.15.2)
Pillow (2.8.1)
pip (8.1.2)
psycopg2 (2.6)
python-apt (0.9.3.12)
python-dateutil (2.5.3)
python-debian (0.1.27)
scipy (0.18.1)
setuptools (28.6.1)
simplejson (3.8.2)
urllib3 (1.9.1)
wheel (0.24.0)
You are using pip version 8.1.2, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(venv) stam#stam:~$
now starting a python interpreter and trying to import cvxopt (note it is in the list above) gives me a importError. Why is this? I'm using the right python version, I work on the venv so everything should work out of the box.
(venv) stam#stam:~$ python
Python 2.7.9 (default, Aug 13 2016, 16:41:35)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import cvxopt
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named cvxopt
>>>
I'm a bit lost and don't know how exactly I can resolve this issue. It seems the right python version is started, at least the one I've attached to the virtualenv.
Additional outps asked for in the comments
(venv) stam#stam:~$ which python
/usr/bin/python
(venv) stam#stam:~$ which pip
/usr/local/bin/pip
Based on the output from which it seems clear that your python and pip belong to two different instances. So all libraries you install will be installed for some other python instance.
The acute fix is to force pip to run through your specified interpreter:
python -m pip list --local
python -m pip install cvxopt

Problems installing ntlk on Mac OSX

I'm trying to install ntlk for a Django project. I followed the intstructions on NTLK's website, and I they worked because when I try to install again with pip, I get:
➜ Word_Maker git:(master) sudo pip install -U numpy
Requirement already up-to-date: numpy in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages
Cleaning up...
➜ Word_Maker git:(master) sudo pip install -U pyyaml nltk
Requirement already up-to-date: pyyaml in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages
Requirement already up-to-date: nltk in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages
Cleaning up...
However, when I do import ntlk from python3, I get:
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 16 2013, 23:39:35)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/nltk/__init__.py", line 37
except IOError, ex:
^
SyntaxError: invalid syntax
^
SyntaxError: invalid syntax
import numpy works, however. Any help would be appreciated!
It seems you made a spelling mistake:
Requirement already up-to-date: nltk in /Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages
And you're trying to import ntlk. Try using import nltk.
As for the import error, the following from their website:
NLTK requires Python versions 2.6-2.7. (A version supporting Python 3 is available at http://nltk.org/nltk3-alpha/).
So NLTK does not (yet) support python 3.3 fully.
First remove NLTK using pip: sudo pip uninstall nltk
Then download the source. And install using sudo python setup.py install
And try again. Be aware this is an alpha, so expect some methods to randomly throw errors or generate unexpected output.
If you still have this error after fixing the spelling, the issue is that PyPI is installing an older NLTK package (2.x). Check this by looking at the first message in the terminal immediately after your run sudo pip install nltk.
To install the latest version of NLTK (3.x) that is compatible with Python 3, first sudo pip uninstall nltk.
Then use:
sudo pip install nltk==3.0.0b2
The latest version number is found here: https://pypi.python.org/pypi/nltk
Sometimes the versions of dependent packages may cause issues. The main issue is old, but I found a slightly different problem when using the parser - which internally was going into scipy. Solved using:
pip3 uninstall nltk scipy matplotlib
pip3 install -U nltk scipy matplotlib

Categories