Can't install NLTK with setup.py - python

I have installed python 2.7 and am trying to set up nltk to do some data analysis (I'm fairly new to the whole programming game). However, I can't seem to install nltk. I downloaded setuptools but it keeps telling me that it can't be found. Do any of you python masters know how to fix this? :)
$ python ez_setup.py
ez_setup.py:129: Warning: 'as' will become a reserved keyword in Python 2.6
File "ez_setup.py", line 129
except pkg_resources.VersionConflict as VC_err:
^
SyntaxError: invalid syntax
$ sudo git clone https://github.com/nltk/nltk.git
Password:
Cloning into 'nltk'...
remote: Reusing existing pack: 48415, done.
remote: Counting objects: 7, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 48422 (delta 0), reused 2 (delta 0)
Receiving objects: 100% (48422/48422), 65.84 MiB | 1.78 MiB/s, done.
Resolving deltas: 100% (32659/32659), done.
Checking connectivity... done
$ cd nltk
$ python setup.py install
Traceback (most recent call last):
File "setup.py", line 33, in <module>
from setuptools import setup, find_packages
ImportError: No module named setuptools

It seems you do not have python2.7-dev is not installed.
Try installing python2.7-dev as below and try running setup again.
$ sudo apt-get install python2.7-dev
$ sudo python setup.py install

Related

Can't install python packages on my ubuntu virtual machine

This is the full script:
(venv) ubuntu#ubuntu:~$ pip install wxPython
Collecting wxPython
Using cached wxPython-4.2.0.tar.gz (71.0 MB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [12 lines of output]
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-jlwwpkvj/wxpython_66c7996a596740a4b92c4f3a3724336d/setup.py", line 27, in <module>
from buildtools.config import Config, msg, opj, runcmd, canGetSOName, getSOName
File "/tmp/pip-install-jlwwpkvj/wxpython_66c7996a596740a4b92c4f3a3724336d/buildtools/config.py", line 30, in <module>
from attrdict import AttrDict
File "/home/ubuntu/PycharmProjects/pythonProject/venv/lib/python3.10/site-packages/attrdict/__init__.py", line 5, in <module>
from attrdict.mapping import AttrMap
File "/home/ubuntu/PycharmProjects/pythonProject/venv/lib/python3.10/site-packages/attrdict/mapping.py", line 4, in <module>
from collections import Mapping
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.10/collections/__init__.py)
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed
× Encountered error while generating package metadata.
╰─> See above for output.
note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
(venv) ubuntu#ubuntu:~$
I think cause of the problem is virtuel machine. I can download packages on my host OS.
I am using UTM for ubuntu.
I try updating pip and setuptolls. I reinstalled differently ubuntu for multiple times.
I am searcing forums for weeks and still nothing.
You need to use an older version of Python (I am guessing 3.9). The best option is probably to set it up in virtualenv like this:
sudo apt update
sudo apt install python3.9
sudo apt-get install python3.9-dev python3.9-venv
python3.9 -m venv myenv
source venv/bin/activate
pip install wxPython
Try to download the wheel (*.whl) file for that package and then:
pip install <wheel file path>

Installing av lib on Raspi3 failing

Excuse me if this is a noob's question, but I am blank if it comes to Python...
I am trying to install the Python av library on a Raspberry Pi 3. But all I get is
pi#raspberrypi:~/camera_proxy $ sudo pip install av
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Collecting av
Downloading https://files.pythonhosted.org/packages/40/e6/da37b548e9e1312fb11ffd0f31f8679e1b96d3859790a77e93a113394d34/av-8.0.3.tar.gz (2.3MB)
100% |████████████████████████████████| 2.3MB 49kB/s
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-install-Mwk4pG/av/setup.py", line 9, in <module>
from shlex import quote
ImportError: cannot import name quote
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-Mwk4pG/av/
I already purged and reinstalled all Python (1&3) to no avail. The Raspbian is the latest stable release.
There seems to be a quote item not found, that supposedly would be part of the shlex library?
The solution for me was to use pip3 instead of pip.

How to install PyAutoGUI on Fedora 27

When I run
sudo pip3 install PyAutoGUI
I receive the following error
[root#localhost Projects]# sudo pip install pyautogui
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip install --user` instead.
Collecting pyautogui
Using cached PyAutoGUI-0.9.36.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-ywXbn7/pyautogui/setup.py", line 6, in <module>
version=__import__('pyautogui').__version__,
File "pyautogui/__init__.py", line 115, in <module>
from . import _pyautogui_x11 as platformModule
File "pyautogui/_pyautogui_x11.py", line 7, in <module>
from Xlib.display import Display
ImportError: No module named Xlib.display
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ywXbn7/pyautogui/
I have followed other troubleshooting advice by installing Pillow and Display and using just the pip command.
I have also attempted installation of PyAutoGUI by cloning the package from GitHub and installing that way, however the following error message is returned:
[root#localhost Projects]# git clone https://github.com/asweigart/pyautogui
Cloning into 'pyautogui'...
remote: Counting objects: 1079, done.
remote: Total 1079 (delta 0), reused 0 (delta 0), pack-reused 1079
Receiving objects: 100% (1079/1079), 2.03 MiB | 697.00 KiB/s, done.
Resolving deltas: 100% (733/733), done.
[root#localhost Projects]# cd pyautogui
[root#localhost pyautogui]# sudo python3 setup.py install
Traceback (most recent call last):
File "setup.py", line 6, in <module>
version=__import__('pyautogui').__version__,
File "/home/luke/Projects/pyautogui/pyautogui/__init__.py", line 115, in <module>
from . import _pyautogui_x11 as platformModule
File "/home/luke/Projects/pyautogui/pyautogui/_pyautogui_x11.py", line 160, in <module>
_display = Display(os.environ['DISPLAY'])
File "/usr/local/lib/python3.6/site-packages/Xlib/display.py", line 80, in __init__
self.display = _BaseDisplay(display)
File "/usr/local/lib/python3.6/site-packages/Xlib/display.py", line 62, in __init__
display.Display.__init__(*(self, ) + args, **keys)
File "/usr/local/lib/python3.6/site-packages/Xlib/protocol/display.py", line 129, in __init__
raise error.DisplayConnectionError(self.display_name, r.reason)
Xlib.error.DisplayConnectionError: Can't connect to display ":0": b'No protocol specified\n'
I am following the instructions from Chapter 18 of Automate the Boring Stuff with the commands slightly altered to suit Fedora 27 Workstation.
This answer is tested on Fedora 30.
First install dependencies
sudo dnf install scrot
sudo dnf install python3-tkinter
sudo dnf install python3-devel.x86_64
Then install PyAutoGUI with pip (without sudo/root)
pip3 install --user python3-xlib
pip3 install --user pyautogui
Note:
PyAutoGUI seems to require X, which is not default in Ferodra 30, but can be chosen at the login screen. Look for Xorg.
(Side note: When installing software, it is recommended to use sudo, if you are logged on as root, there is no need for sudo)

Python 3: Installing gi package with pip

I am trying to run this Matplotlib example using Python 3. To run this I needed to install gi first (I am using pyenv):
$ python --version
Python 3.6.1
$ pip --version
pip 9.0.1 from /home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages (python 3.6)
$ pip install gi
Collecting gi
Downloading gi-1.2.tar.gz
Collecting requests (from gi)
Downloading requests-2.16.0-py2.py3-none-any.whl (85kB)
100% |████████████████████████████████| 92kB 959kB/s
Collecting idna<2.6,>=2.5 (from requests->gi)
Downloading idna-2.5-py2.py3-none-any.whl (55kB)
100% |████████████████████████████████| 61kB 1.2MB/s
Collecting chardet<3.1.0,>=3.0.2 (from requests->gi)
Downloading chardet-3.0.3-py2.py3-none-any.whl (133kB)
100% |████████████████████████████████| 143kB 1.8MB/s
Collecting urllib3<1.22,>=1.21.1 (from requests->gi)
Downloading urllib3-1.21.1-py2.py3-none-any.whl (131kB)
100% |████████████████████████████████| 133kB 1.8MB/s
Collecting certifi>=2017.4.17 (from requests->gi)
Downloading certifi-2017.4.17-py2.py3-none-any.whl (375kB)
100% |████████████████████████████████| 378kB 284kB/s
Installing collected packages: idna, chardet, urllib3, certifi, requests, gi
Running setup.py install for gi ... done
Successfully installed certifi-2017.4.17 chardet-3.0.3 gi-1.2 idna-2.5 requests-2.16.0 urllib3-1.21.1
Now, running the example:
$ python toolmanager.py
Traceback (most recent call last):
File "./toolmanager.py", line 8, in <module>
import matplotlib.pyplot as plt
File "/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3cairo.py", line 6, in <module>
from . import backend_gtk3
File "/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py", line 10, in <module>
import gi
File "/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages/gi/__init__.py", line 39
print url
^
SyntaxError: Missing parentheses in call to 'print'
Seems like pip somehow installed a Python 2 version? How can I fix this?
First, pip install gi will install another unrelated package, the correct
name is pgi. But after running:
$ pip uninstall gi
$ pip install pgi
$ python toolmanager.py
[...]
Traceback (most recent call last):
File "toolmanager.py", line 14, in <module>
import matplotlib.pyplot as plt
File "/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages/matplotlib/pyplot.py", line 115, in <module>
_backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
File "/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages/matplotlib/backends/__init__.py", line 32, in pylab_setup
globals(),locals(),[backend_name],0)
File "/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3cairo.py", line 6, in <module>
from . import backend_gtk3
File "/home/hakon/.pyenv/versions/3.6.1/lib/python3.6/site-packages/matplotlib/backends/backend_gtk3.py", line 12, in <module>
raise ImportError("Gtk3 backend requires pygobject to be installed.")
ImportError: Gtk3 backend requires pygobject to be installed.
It seems that pygobject for Python 3 cannot be installed from PyPI. So I tried to install everything from the Ubuntu distribution package python3-gi instead:
$ sudo apt-get install python3-gi
$ pyenv local system
$ python3 --version
Python 3.5.3
$ python3 toolmanager.py
and this works fine :)
The chosen answer is a little bit outdated as of now:
Last update of pgi in 2018
Since 2018, PyGObject is available for python3 from PyPI.
Installing the relevant package, plus its dependencies, depending on your environment, is still possible, just follow the steps from the doc.
But if you work from a venv, you might still stumble upon a ModuleNotFoundError: No module named 'gi' when importing gi. The venv ignores the system-wide module. Then simply run, from your venv: pip install PyGObject (or use poetry or your favorite python packages manager). Of course, you still need to have installed PyGObject's dependencies (see the link to the doc, right above).
To install for the standard python, Håkon Hægland answer is the best choice.
But for an alternate python version,
one can use pip<version>.
Beware that the alternate pip has to be used to match the alternate python.
The full explanations are given in the documentation.
For instance on openSUSE (standard python version 3.6, alternate installed 3.8):
> sudo zypper install cairo-devel pkg-config python3-devel gcc gobject-introspection-devel
> pip3.8 install --user pycairo
> pip3.8 install --user PyGObject
> python3.8
Python 3.8.1 (default, Feb 1 2020, 14:50:41)
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gi
>>>

Django project at Heroku cannot install dependencies with pip

i'm trying to deploy a django project on Heroku. I use virtualenv and pip to manage dependencies. The virtualenv version is 1.7.1 and pip that comes with it it's 1.1. I tried to force the --no-site-packages but it prompts that it's the default behavior now. Also i'm sure that i install everything within the virtual environment. The django project it's empty. I followed the instructions here . Maybe the problem it's that their versions of pip and virtualenv are older? Has anyone encountered this problem? Thank you in advance.
ψ pip.exe freeze
Django==1.3.1
distribute==0.6.24
versiontools==1.8.3
(venv)
ψ more .\requirements.txt
Django==1.3.1
distribute==0.6.24
versiontools==1.8.3
(venv)
ψ git push heroku master
Enter passphrase for key '/c/Program Files (x86)/Vim/.ssh/id_rsa':
Counting objects: 12, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (10/10), done.
Writing objects: 100% (12/12), 3.30 KiB, done.
Total 12 (delta 2), reused 0 (delta 0)
-----> Heroku receiving push
-----> Python/Django app detected
-----> Preparing virtualenv version 1.7
New python executable in ./bin/python
Installing distribute.............................................................................................................................................................................................done.
Installing pip...............done.
-----> Activating virtualenv
-----> Installing dependencies using pip version 1.0.2
Exception:
Traceback (most recent call last):
File "/tmp/build_k6zl66ydgqxp/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/basecommand.py", line 126, in main
self.run(options, args)
File "/tmp/build_k6zl66ydgqxp/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/commands/install.py", line 200, in run
for req in parse_requirements(filename, finder=finder, options=options):
File "/tmp/build_k6zl66ydgqxp/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/req.py", line 1255, in parse_requirements
req = InstallRequirement.from_line(line, comes_from)
File "/tmp/build_k6zl66ydgqxp/lib/python2.7/site-packages/pip-1.0.2-py2.7.egg/pip/req.py", line 82, in from_line
elif os.path.isdir(path) and (os.path.sep in name or name.startswith('.')):
File "/tmp/build_k6zl66ydgqxp/lib/python2.7/genericpath.py", line 41, in isdir
st = os.stat(s)
TypeError: must be encoded string without NULL bytes, not str
Storing complete log in /app/.pip/pip.log
! Heroku push rejected, failed to compile Python/django app
It seems that the problem it is in the requirements.txt, i created it using powershell and "pip.exe freeze > requirements.txt" command,
which creates a file with a name that has nullbytes in it.
I was able to get around this problem by downloading a requirements.txt from an example project on github and modifying it.
That did the job and everything works nice.

Categories

Resources