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
>>>
Related
I'm trying to install the pygmentize module on a Windows XP computer which uses Python 3.3.6 (Sep 29th, 2012)
When I did pip install pygmentize it returned windows XP Fatal error in launcher: Unable to create process so I've applied this solution and here it is how went:
$ python -m pip install --upgrade pip
Collecting pip
Downloading https://files.pythonhosted.org/packages/8a/d7/f505e91e2cdea53cfcf51f4ac478a8cd64fb0629cedde20d9a6a9b/pip-21.2.2-py3-none-any.whl (1.6MB)
100% |################################| 1.6MB 87kB/s
Installing collected packages: pip
Found existing installation: pip 7.1.2
Uninstalling pip-7.1.2:
Successfully uninstalled pip-7.1.2
Successfully installed pip-21.2.2
When I've tried to install again:
$ pip install pygmentize
Traceback (most recent call last):
File "c:\programs\python-3.3\lib\runpy.py", line 160, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "c:\programs\python-3.3\lib\runpy.py", line 73, in _run_code
exec(code, run_globals)
File "C:\Programs\python-3.3\Scripts\pip.exe\__main__.py", line 5, in <module>
File "c:\programs\python-3.3\lib\site-packages\pip\__init__.py", line 1, in <module>
from typing import List, Optional
ImportError: No module named 'typing'
Assuming that pip-21.2.2 is fully compatible with pyrhon-3.3.6 I think it's caused by my python-3.3.6 being incompatible with the current version of pygmentize If that is the case how can I check which version of pygmentize is compatible with python-3.3.6 and how can I install that compatible version of it in python-3.3.6 ?
If you use pycharm you can go to "python-packages" and search for pygmentize then install it
We have CentOS 7 servers in a Hadoop cluster. Python and pip should have been installed on all of the server the same way because it was done with Ansible. But for some reason, there are some servers where Python cannot use the modules that were installed. For instance pandas was install, but when in python3.6, I get a 'No module named pandas' error.
$ python3.6
Python 3.6.2 (default, Aug 2 2017, 14:51:00)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pandas'
>>>
If I try installing pandas again, I get messages that the reuirements are already satisfied.
$ sudo pip3.6 install pandas
Requirement already satisfied: pandas in /usr/lib64/python3.6/site-packages
Requirement already satisfied: python-dateutil>=2 in /usr/lib/python3.6/site-packages (from pandas)
Requirement already satisfied: pytz>=2011k in /usr/lib/python3.6/site-packages (from pandas)
Requirement already satisfied: numpy>=1.9.0 in /usr/lib64/python3.6/site-packages (from pandas)
Requirement already satisfied: six>=1.5 in /usr/lib/python3.6/site-packages (from python-dateutil>=2->pandas)
It appears that the python 3.6 sys.path is using a different location for site-packages.
$ python3.6 -m site
sys.path = [
'/home/avalenti',
'/usr/local/lib/python36.zip',
'/usr/local/lib/python3.6',
'/usr/local/lib/python3.6/lib-dynload',
'/usr/local/lib/python3.6/site-packages',
]
It may all stem from pip being installed in an unusual location.
$ pip3.6 --version
pip 9.0.1 from /usr/lib/python3.6/site-packages (python 3.6)
Pip and the modules seem to be located in the same place, correctly on servers that DO work as follows:
$ pip3.6 --version
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)
$ python3.6 -m site
sys.path = [
'/home/avalenti',
'/usr/local/lib/python36.zip',
'/usr/local/lib/python3.6',
'/usr/local/lib/python3.6/lib-dynload',
'/usr/local/lib/python3.6/site-packages',
]
$ python3.6
Python 3.6.2 (default, Aug 2 2017, 14:17:20)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
>>> exit()
$ pip3.6 show pandas
Name: pandas
Version: 0.22.0
Summary: Powerful data structures for data analysis, time series,and statistics
Home-page: http://pandas.pydata.org
Author: The PyData Development Team
Author-email: pydata#googlegroups.com
License: BSD
Location: /usr/local/lib/python3.6/site-packages
Requires: numpy, pytz, python-dateutil
So my question is, how do I get this fixed and how do I keep this from happening in the first place? I don't seem to find a way to configure Pip and I don't find any way to specify the installation location for modules.
I tried to be thorough with the information provided, but I'm sure I missed something.
Thanks,
Anthony
Well, the Pip documentation for the config pointed me to the --target option for pip install. That allowed me to specify the location where I thought the packages should go - /usr/local/lib/python3.6/site-packages (as noted in the sys.path). That allowed the import to find the pandas package, but fail on the import of some basic system modules, builtin and binascii. It seems like python itself is kinda hosed.
# pip3.6 install --target /usr/local/lib/python3.6/site-packages pandas
Collecting pandas
Using cached pandas-0.22.0-cp36-cp36m-manylinux1_x86_64.whl
Collecting numpy>=1.9.0 (from pandas)
Downloading numpy-1.14.2-cp36-cp36m-manylinux1_x86_64.whl (12.2MB)
100% |████████████████████████████████| 12.2MB 92kB/s
Collecting python-dateutil>=2 (from pandas)
Downloading python_dateutil-2.7.2-py2.py3-none-any.whl (212kB)
100% |████████████████████████████████| 215kB 2.4MB/s
Collecting pytz>=2011k (from pandas)
Using cached pytz-2018.3-py2.py3-none-any.whl
Collecting six>=1.5 (from python-dateutil>=2->pandas)
Using cached six-1.11.0-py2.py3-none-any.whl
Installing collected packages: numpy, six, python-dateutil, pytz, pandas
Successfully installed numpy-1.14.2 pandas-0.22.0 python-dateutil-2.7.2 pytz-2018.3 six-1.11.0
You are using pip version 9.0.1, however version 9.0.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
# python3.6
Python 3.6.2 (default, Aug 2 2017, 14:51:00)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/pandas/compat/__init__.py", line 48, in <module>
import __builtin__ as builtins
ModuleNotFoundError: No module named '__builtin__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.6/site-packages/pandas/__init__.py", line 23, in <module>
from pandas.compat.numpy import *
File "/usr/local/lib/python3.6/site-packages/pandas/compat/__init__.py", line 61, in <module>
import http.client as httplib
File "/usr/local/lib/python3.6/http/client.py", line 71, in <module>
import email.parser
File "/usr/local/lib/python3.6/email/parser.py", line 12, in <module>
from email.feedparser import FeedParser, BytesFeedParser
File "/usr/local/lib/python3.6/email/feedparser.py", line 27, in <module>
from email._policybase import compat32
File "/usr/local/lib/python3.6/email/_policybase.py", line 7, in <module>
from email import header
File "/usr/local/lib/python3.6/email/header.py", line 14, in <module>
import binascii
ModuleNotFoundError: No module named 'binascii'
>>> exit()
Ugh...
You need to be very careful using pip when having multiple Python distributions. Instead of using pip3.6', try usingpython3.6 -m pip` to install pandas:
python3.6 -m pip install pandas
(prepend sudo if you really need to). In this way you are invoking pip through Python itself, and so you are guaranteed to get the pip that belongs with the Python you want.
You can try to set the location for pip in $HOME/.pip/pip.conf
As per PIP Docs:
Configuration Config file
pip allows you to set all command line option defaults in a standard
ini style config file.
The names and locations of the configuration files vary slightly
across platforms. You may have per-user, per-virtualenv or site-wide
(shared amongst all users) configuration:
Per-user:
On Unix the default configuration file is: $HOME/.config/pip/pip.conf which respects the XDG_CONFIG_HOME
environment variable.
On macOS the configuration file is $HOME/Library/Application Support/pip/pip.conf.
On Windows the configuration file is %APPDATA%\pip\pip.ini.
There are also a legacy per-user configuration file which is also
respected, these are located at:
On Unix and macOS the configuration file is: $HOME/.pip/pip.conf
On Windows the configuration file is: %HOME%\pip\pip.ini
You can set a custom path location for this config file using the
environment variable PIP_CONFIG_FILE.
Inside a virtualenv:
On Unix and macOS the file is $VIRTUAL_ENV/pip.conf
On Windows the file is: %VIRTUAL_ENV%\pip.ini
Site-wide:
On Unix the file may be located in /etc/pip.conf. Alternatively it may be in a "pip" subdirectory of any of the paths set in the
environment variable XDG_CONFIG_DIRS (if it exists), for example
/etc/xdg/pip/pip.conf.
On macOS the file is: /Library/Application Support/pip/pip.conf
On Windows XP the file is: C:\Documents and Settings\All Users\Application Data\pip\pip.ini
On Windows 7 and later the file is hidden, but writeable at C:\ProgramData\pip\pip.ini
Site-wide configuration is not supported on Windows Vista
If multiple configuration files are found by pip then they are
combined in the following order:
Firstly the site-wide file is read, then
The per-user file is read, and finally
The virtualenv-specific file is read.
Each file read overrides any values read from previous files, so if
the global timeout is specified in both the site-wide file and the
per-user file then the latter value is the one that will be used.
Short answer, but I would recommend using Python Virtual Environments. Makes managing Python versions and pip packages very easy.
https://docs.python.org/3/tutorial/venv.html
This way you can have many different virtualized Python environments and activate them for whatever script, Ansible playbook, etc you are running. Another great feature is you can create a requirements file to share with others, so if they want to run your code they can simply install from the requirements file which guarantees they have the right version of Python and associated packages installed.
I am trying to install upstox, which is a Python API for connecting to market data. I am unable to install it on Python3.5.
My config is
Python 3.5.3 (v3.5.3:1880cb95a742, Jan 16 2017, 15:51:26) [MSC v.1900 32 bit (Intel)] on win32. And the error I keep getting is:
Collecting upstox
Using cached upstox-0.7-py2.py3-none-any.whl
Collecting future (from upstox)
Using cached future-0.16.0.tar.gz
Collecting websocket-client (from upstox)
Using cached websocket_client-0.42.1-py2.py3-none-any.whl
Collecting pycurl (from upstox)
Using cached pycurl-7.43.0-cp35-none-win32.whl
Collecting enum (from upstox)
Using cached enum-0.4.6.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\UserPad\AppData\Local\Programs\Python\Python35-32\lib\site-packages\setuptools\__init__.py", line 10, in <module>
from setuptools.extern.six.moves import filter, filterfalse, map
File "C:\Users\UserPad\AppData\Local\Programs\Python\Python35-32\lib\site-packages\setuptools\extern\__init__.py", line 1, in <module>
from pkg_resources.extern import VendorImporter
File "C:\Users\UserPad\AppData\Local\Programs\Python\Python35-32\lib\site-packages\pkg_resources\__init__.py", line 33, in <module>
import platform
File "C:\Users\UserPad\AppData\Local\Programs\Python\Python35-32\lib\platform.py", line 117, in <module>
import sys, os, re, subprocess
File "C:\Users\UserPad\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 50, in <module>
import signal
File "C:\Users\UserPad\AppData\Local\Programs\Python\Python35-32\lib\signal.py", line 4, in <module>
from enum import IntEnum as _IntEnum
ImportError: cannot import name 'IntEnum'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in C:\Users\UserPad\AppData\Local\Temp\pycharm-packaging\enum\
for python2
sudo pip2 install -U enum
for python3
sudo pip3 install -U enum34
pip install enum34
will solve the issue
i named file as enum.py and recive that result
rename and all
for python2, we need both enum and enum34
pip install enum
pip install enum34
Have you installed enum before installing your desired package? It looks like it wants you to install it first.
Run this command in CMD to install enum, and then try installing your desired package:
pip install enum
This has me pretty confused. I've installed pyad using pip and everything seems fine:
C:\WINDOWS\system32>pip install pyad
Collecting pyad
Using cached pyad-0.5.16.tar.gz
Requirement already satisfied (use --upgrade to upgrade): setuptools in c:\python35\lib\site-packages (from pyad)
Requirement already satisfied (use --upgrade to upgrade): pywin32 in c:\python35\lib\site-packages (from pyad)
Installing collected packages: pyad
Running setup.py install for pyad ... done
Successfully installed pyad-0.5.16
But when I try to use it, I get an error that complains about not finding adbase:
C:\WINDOWS\system32>python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from pyad import aduser
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python35\lib\site-packages\pyad\__init__.py", line 1, in <module>
from adbase import set_defaults as pyad_setdefaults
ImportError: No module named 'adbase'
>>> import pyad
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python35\lib\site-packages\pyad\__init__.py", line 1, in <module>
from adbase import set_defaults as pyad_setdefaults
ImportError: No module named 'adbase'
This is odd, because if I try to uninstall pyad or if I check the site-packages directory, adbase is definitely there:
C:\WINDOWS\system32>pip uninstall pyad
Uninstalling pyad-0.5.16:
c:\python35\lib\site-packages\pyad-0.5.16-py3.5.egg-info
c:\python35\lib\site-packages\pyad\__init__.py
c:\python35\lib\site-packages\pyad\__pycache__\__init__.cpython-35.pyc
c:\python35\lib\site-packages\pyad\__pycache__\adcomputer.cpython-35.pyc
c:\python35\lib\site-packages\pyad\__pycache__\addomain.cpython-35.pyc
c:\python35\lib\site-packages\pyad\__pycache__\adgroup.cpython-35.pyc
c:\python35\lib\site-packages\pyad\__pycache__\adquery.cpython-35.pyc
c:\python35\lib\site-packages\pyad\__pycache__\adsearch.cpython-35.pyc
c:\python35\lib\site-packages\pyad\__pycache__\pyad.cpython-35.pyc
c:\python35\lib\site-packages\pyad\adbase.py
c:\python35\lib\site-packages\pyad\adcomputer.py
c:\python35\lib\site-packages\pyad\adcontainer.py
c:\python35\lib\site-packages\pyad\addomain.py
c:\python35\lib\site-packages\pyad\adgroup.py
c:\python35\lib\site-packages\pyad\adobject.py
c:\python35\lib\site-packages\pyad\adquery.py
c:\python35\lib\site-packages\pyad\adsearch.py
c:\python35\lib\site-packages\pyad\aduser.py
c:\python35\lib\site-packages\pyad\pyad.py
c:\python35\lib\site-packages\pyad\pyadconstants.py
c:\python35\lib\site-packages\pyad\pyadexceptions.py
c:\python35\lib\site-packages\pyad\pyadutils.py
Proceed (y/n)?
pyad directory contents
I'm really not sure what else to try. I've run everything under an elevated command prompt, so it's not a permissions issue. I even tried downloading pyad and installing it using setup.py, but I had the same problem with that. adbase is definitely there, and I can't figure out why Python isn't finding it.
That's a bug on pyad part. They're importing adbase as if it were a standalone module or package, and that's why it does not work. The proper way to fix this would be to change the import to an absolute import from pyad.adbase import ... or relative from .adbase import ....
However, if you check the master branch on Github, you will see that they have actually fixed it. But that's not all, if you check their setup.py you'll see that the version on Github is 0.5.15, while the last version on PyPI, which is the one you have installed, is 0.5.16. Weird.
I suggest you to install the package directly from Github, and that should take care of the problem. To do that, first uninstall pyad and then run
pip install https://github.com/zakird/pyad/archive/master.zip
I'm trying to get up and running with an ipython plugin for gedit3, but it requires ipython-listener, and when I try to launch it I get this:
Traceback (most recent call last):
File "/usr/local/bin/ipython-listener", line 27, in <module>
from IPython.frontend.terminal.embed import InteractiveShellEmbed
ImportError: No module named terminal.embed
I'm running ipython version 0.10.2 and python version 2.7.2+
I tried to do pip install terminal.embed but couldn't find it:
Downloading/unpacking terminal.embed
Could not find any downloads that satisfy the requirement terminal.embed
No distributions at all found for terminal.embed
Storing complete log in /home/amanda/.pip/pip.log
So now what?
I tried to do pip install terminal.embed but couldn't find it
It's not a package, it's part of IPython. Your IPython is just too old (by a couple of years).
That plugin depends on IPython ≥ 0.11 (current is 0.13.1). Try:
pip install --upgrade ipython