Python newbie here.
I'm trying to do a scraper in Python3, but I'm having problems importing lxml on my Sierra 10.12.
Here's the process and additional info:
$ python3 --version
Python 3.5.1
$ pip3 install lxml
Requirement already satisfied: lxml in /usr/local/lib/python3.6/site-packages
$ python3
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'lxml'
>>>
Am I doing something wrong? Is there any other way to install a module?
I noticed that lxml seems to be installed on python 3.6 folder, even though my python3 version is 3.5.1, is that what's wrong?
EDIT: I tried the same thing with python 2.7 and got the same result.
$ python --version
Python 2.7.10
$ pip install lxml
Requirement already satisfied: lxml in /usr/local/lib/python2.7/site-packages
$ python2.7
Python 2.7.10 (default, Feb 7 2017, 00:08:15)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import lxml
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'lxml'
>>>
Related
Actually I already installed tensorflow by using
$ pip install tensorflow
and it works well when I use
$ python
Python 2.7.15 (default, Jul 23 2018, 21:27:06)
[GCC 4.2.1 Compatible Apple LLVM 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>import tensorflow
>>>
but when I use python3 on command line
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 26 2018, 23:26:24)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
>>>
it shows an error, and it shows the same error when I use IDLE
use
pip3 install tensorflow
pip installs to default python directory. pip3 installs to python3
I'm trying to get this Python 2.7 code to work.
https://github.com/slanglab/phrasemachine
I've downloaded and unzipped the repo from github. Here's what happens when I try to run the code.
phrasemachine$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import phrasemachine
>>> text = "Barack Obama supports expanding social security."
>>> print phrasemachine.get_phrases(text)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "phrasemachine.py", line 253, in get_phrases
tagger = TAGGER_NAMES[tagger]()
File "phrasemachine.py", line 166, in get_stdeng_nltk_tagger
tagger = NLTKTagger()
File "phrasemachine.py", line 133, in __init__
import nltk
ImportError: No module named nltk
So, I need the nltk module. I have that installed here:
Sure enough, Python 2 doesn't know about nltk.
phrasemachine$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named nltk
But, Python 3 does.
phrasemachine$ python3
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 5 2015, 21:12:44)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import nltk
>>>
Pip tells me that nltk is already installed, but for 3.5.
$ sudo pip install -U nltk
Requirement already up-to-date: nltk in /Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/nltk-3.2.1-py3.5.egg
Update 10/10/16: I installed the 2.7 version of Python via brew, which give me the 2.7 pip.
$ /usr/local/bin/pip --version
pip 8.1.2 from /usr/local/lib/python2.7/site-packages (python 2.7)
Then I installed nltk with that pip:
$ sudo /usr/local/bin/pip install -U nltk
Password:
The directory '/Users/me/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/me/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.
Collecting nltk
Downloading nltk-3.2.1.tar.gz (1.1MB)
100% |████████████████████████████████| 1.1MB 683kB/s
Installing collected packages: nltk
Running setup.py install for nltk ... done
Successfully installed nltk-3.2.1
It says it installed nltk but the warnings are concerning. And, Python 2.7 still fails to import nltk.
$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import phrasemachine
>>> text = "Barack Obama supports expanding social security."
>>> print phrasemachine.get_phrases(text)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "phrasemachine.py", line 253, in get_phrases
tagger = TAGGER_NAMES[tagger]()
File "phrasemachine.py", line 166, in get_stdeng_nltk_tagger
tagger = NLTKTagger()
File "phrasemachine.py", line 133, in __init__
import nltk
ImportError: No module named nltk
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named nltk
Final update! I pointed Python 2.7 to the site packages directory where Homebrew installs stuff and I'm now good!
>>> import sys
>>> sys.path.append('/usr/local/lib/python2.7/site-packages')
Since you have two python distributions, you also need two versions of pip. Find out where your pip executables are with which -a pip, and install pip for your Python 2.7 distribution if necessary. Then tell the pip that goes with Python 2.7 (perhaps /usr/local/bin/pip) to install the nltk.
(Edit: Pip must be able to find the proper Python on its PATH. I hadn't thought to go into this.)
I installed Pillow using Anaconda but if I cannot load the module (see below). How coudl I fix this?
dhcp-86-216:Python_code Alberto$ pip install Pillow
Requirement already satisfied (use --upgrade to upgrade): Pillow in /Users/Alberto/anaconda/lib/python2.7/site-packages
Cleaning up...
dhcp-86-216:Python_code Alberto$ python
Python 2.7.6 (v2.7.6:3a1db0d2747e, Nov 10 2013, 00:42:54)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import Pillow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Pillow
Import PIL, not Pillow:
import PIL
I am using MacOS X 10.7.5 and am a TOTAL newb at Python
I am pretty sure django installed correctly as per https://code.djangoproject.com/wiki/Distributions
$ sudo port install py27-django
---> Computing dependencies for py27-django
---> Cleaning py27-django
---> Scanning binaries for linking errors: 100.0%
---> No broken files found.
$ python
Python 2.7.1 (r271:86832, Jun 16 2011, 16:59:05)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named django
The issue was with that a prior Python was installed (2.7.1) previously and MacPorts installed a new one (2.7.6) but did not update the Mac Sym links etc
So I had to futz with my PATH
$ vi ~/.bash_profile
.
.
export PATH=/opt/local/Library/Frameworks/Python.framework/Versions/2.7/bin:$PATH
.
.
$ source ~/.bash_profile
$ python --version
Python 2.7.6
$ python
Python 2.7.6 (default, Nov 12 2013, 13:12:10)
[GCC 4.2.1 Compatible Apple Clang 4.1 ((tags/Apple/clang-421.11.66))] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> print django.get_version()
1.5.1
I've installed Python 3.3 alongside Python 2.75 on my Ubuntu machine. The problem is that easy_install gets packages for the default, 2.75 version only, e.g:
easy_install pymongo
$ python
Python 2.7.4 (default, Apr 19 2013, 18:28:01)
[GCC 4.7.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
>>>
But:
$ python3.3
Python 3.3.1 (default, Apr 17 2013, 22:30:32)
[GCC 4.7.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pymongo
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named 'pymongo'
How can I install PyPi packages for the Python 3.3 installation?
You need easy_install3. In apt-get you get it by
apt-get install python3-setuptools