I have problems to import the matplotlibrary for my python3 script.
My system:
CentOS Linux 7 (Core)
Kernel 3.10.0-1062.9.1.el7.x86_64
Python 3.6.8
Minimal reproduction:
Setup:
python3 -m venv tester
source tester/bin/activate
pip install matplotlib
pip list
Gives:
Package Version
--------------- ---------
certifi 2020.6.20
cycler 0.10.0
kiwisolver 1.2.0
matplotlib 3.3.2
numpy 1.19.2
Pillow 8.0.1
pip 18.1
pyparsing 2.4.7
python-dateutil 2.8.1
setuptools 40.6.2
six 1.15.0
Now to actual reproduction:
python3
>>>from matplotlib import pyplot as plt
Gives:
Traceback (most recent call last):
File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/backends/backend_cairo.py", line 15, in <module>
import cairo
ModuleNotFoundError: No module named 'cairo'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/backends/backend_cairo.py", line 21, in <module>
import cairocffi as cairo
ModuleNotFoundError: No module named 'cairocffi'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2336, in <module>
switch_backend(rcParams["backend"])
File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/pyplot.py", line 276, in switch_backend
class backend_mod(matplotlib.backend_bases._Backend):
File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/pyplot.py", line 277, in backend_mod
locals().update(vars(importlib.import_module(backend_name)))
File "/apps/shared/taifun/x86_64/apps/DATAPROCESSING/python/3.6.8/system/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/gpfs/apps/shared/mpo/tester/lib/python3.6/site-packages/matplotlib/backends/backend_cairo.py", line 25, in <module>
"is installed") from err
ImportError: cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
Ok, so we install pycairo:
pip install pycairo
Gives:
Collecting pycairo
Downloading <internal-package-server>/5a10cb7f9ae0d/pycairo-1.20.0.tar.gz (344kB)
100% |████████████████████████████████| 348kB 3.7MB/s
Installing build dependencies ... done
Installing collected packages: pycairo
Running setup.py install for pycairo ... done
Successfully installed pycairo-1.20.0
Lets check:
pip list
Seems ok:
Package Version
--------------- ---------
...
pycairo 1.20.0
...
New try:
python3
>>>from matplotlib import pyplot as plt
Nope, same error:
...
ImportError: cairo backend requires that pycairo>=1.11.0 or cairocffiis installed
Now, adapting the version to 1.11 works:
pip uninstall pycairo
pip install pycairo==1.11
python3
>>> from matplotlib import pyplot as plt
>>>
Hurray!
But why is pycairo 1.20 not working here? 1.11 -> 1.20 shouldn't be a breaking change and someone else should have notized this issue earlier. What might I be missing? Or should I actually open a ticket at matplotlib so they adapt their req. list?
Thanks in advance.
Ok, I managed to solve the issue. Several steps were necessary:
Switch from pycairo to cairocffi (as CForce99 suggested)
Update pip and setuptools (via entry to the gitlab-cy.yml), old version (40.x) had problems with cairocff's .tar.gz
Set the path to the certificate for my corporate's internal pypi mirror (export REQUEST_CA_BUNDLE)
Related
I want to make handtracker program using python but the tutorial tell me to install mediapipe library, then I installed it. Before that it's okay using cv2 to stream my camera, but after installing mediapipe, the cv2 doesn't work
here the message :
>>>import cv2
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import cv2
File "C:\Users\windows\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\__init__.py", line 181, in <module>
bootstrap()
File "C:\Users\windows\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\__init__.py", line 175, in bootstrap
if __load_extra_py_code_for_module("cv2", submodule, DEBUG):
File "C:\Users\windows\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\__init__.py", line 28, in __load_extra_py_code_for_module
py_module = importlib.import_module(module_name)
File "C:\Users\windows\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "C:\Users\windows\AppData\Local\Programs\Python\Python39\lib\site-packages\cv2\gapi\__init__.py", line 290, in <module>
cv.gapi.wip.GStreamerPipeline = cv.gapi_wip_gst_GStreamerPipeline
AttributeError: partially initialized module 'cv2' has no attribute 'gapi_wip_gst_GStreamerPipeline' (most likely due to a circular import) ```
I tried to install opencv again but always get this message :
Requirement already satisfied: numpy>=1.19.3 in c:\users\windows\appdata\local\programs\python\python39\lib\site-packages (from opencv-python) (1.21.1)
but the problem still there. How do I fix it?
Edited : this is my pip list
C:\Users\windows>pip list
Package Version
--------------------- --------
absl-py 1.1.0
attrs 21.4.0
cycler 0.11.0
fonttools 4.33.3
kiwisolver 1.4.2
matplotlib 3.5.2
mediapipe 0.8.10
numpy 1.21.1
opencv-contrib-python 4.6.0.66
opencv-python 4.5.3.56
packaging 21.3
Pillow 8.3.1
pip 22.1.2
protobuf 4.21.1
pygame 2.1.2
pyparsing 3.0.9
python-dateutil 2.8.2
pyzbar 0.1.8
setuptools 56.0.0
six 1.16.0
I have the same situation like above
you can try it:
pip install "opencv-python-headless<4.3"
This command has successfully resolved this situation
Reference:https://github.com/Rudrabha/Wav2Lip/issues/387
In any version(ex: 4.6.0.66), when you install any 2 of 3 packages: opencv-contrib-python, opencv-python-headless, opencv-python, make sure they have the same version. I also got the same error, I found out their versions are different. Then a synchronous update solved the problem.
I have similar problem, and I only have opencv-python installed. The problem is solved by installing opencv-python-headless.
My problem is more complicate than that. Actually the opencv-python is already installed in "root", but when I login as another user (dev), I get the problem as OP.
I can install opencv-python-headless or opencv-contrib-python manually, then the system will work. But if I install them in "root", I sill have the same problem.
So the final solution I use is to reinstall opencv-python in my user environment (dev):
pip3 install --upgrade --force-reinstall opencv-python
I fix such a problem using the following commands.
pip uninstall opencv-contrib-python
pip install opencv-contrib-python
the following solution
pip install "opencv-python-headless<4.3"
fixed the error below when building OpenCV from source!
import cv2
Traceback (most recent call last):
File "", line 1, in
File "C:\ProgramData\Anaconda3\lib\site-packages\cv2_init_.py", line 181, in
bootstrap()
File "C:\ProgramData\Anaconda3\lib\site-packages\cv2_init_.py", line 153, in bootstrap
native_module = importlib.import_module("cv2")
File "C:\ProgramData\Anaconda3\lib\importlib_init_.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ImportError: DLL load failed while importing cv2: The specified module could not be found.
I successfully installed Tensorflow 2.7.0 on my MacBook with an M1 chip following this guide by Apple: https://developer.apple.com/metal/tensorflow-plugin/
I now want to install a package (ethnicolr) in a project that relies on Tensorflow >=1.15.2. This should not be an issue, but it sadly is.
requirements.txt of my project
pandas==1.3.4
ethnicolr==0.4.0
requirements.txt of ethnicolr:
tensorflow>=1.15.2
Running pip install -r requirements.txt yields
ERROR: Could not find a version that satisfies the requirement
tensorflow>=1.15.2 (from ethnicolr) (from versions: none) ERROR: No
matching distribution found for tensorflow>=1.15.2
Running pip list shows, that Tensorflow was installed. But it's not called tensorflow, but tensorflow-macos or tensorflow-metal.
tensorboard 2.7.0
tensorboard-data-server 0.6.1
tensorboard-plugin-wit 1.8.0
tensorflow-estimator 2.7.0
tensorflow-macos 2.7.0
tensorflow-metal 0.3.0
What is a solution here? There must be more packages out there with the requirement of Tensorflow...
So I got it to run. I'm not sure if this is ideal but I'm sharing my solution to maybe help anyone running into the same issue. I installed tensorflow 2.6.0 in a virtual environment using conda / mambaforge. I opted for 2.6.0 because 2.5.2 is not available for M1 and 2.5.0 wasn't working. You can read about installing Mamaforge here. After that, I installed Tensorflow with
conda install tensorflow==2.6.0
I also set the pandas version to pandas>1.2.3 in the requirements.txt of my own project (same as in ethnicolr). This resolved to pandas 1.3.3.
Next, I had to solve the dependency issue with ethnicolr, since ethnicolr requires tensorflow 2.5.2. I did that by forking the ethnicolr repo and creating a branch where I pin the tensorflow version to 2.6.0 in the requirements.txt and setup.py. You find this branch over here. To use this github branch, I changed the line in my requirements.txt to:
git+https://github.com/ospaarmann/ethnicolr.git#apple_m1_support_tensorflow_2_6_0#egg=ethnicolr
Now I had an issue with a dependency mismatch with numpy. It is described in this StackOverflow thread. What happened was that importing pandas or ethnicolr would throw this error:
>>> from ethnicolr import census_ln, pred_census_ln, pred_wiki_name
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/olespaarmann/mambaforge/envs/diversity_scraper/lib/python3.8/site-packages/ethnicolr/__init__.py", line 2, in <module>
from ethnicolr.census_ln import census_ln
File "/Users/olespaarmann/mambaforge/envs/diversity_scraper/lib/python3.8/site-packages/ethnicolr/census_ln.py", line 6, in <module>
import pandas as pd
File "/Users/olespaarmann/mambaforge/envs/diversity_scraper/lib/python3.8/site-packages/pandas/__init__.py", line 22, in <module>
from pandas.compat import (
File "/Users/olespaarmann/mambaforge/envs/diversity_scraper/lib/python3.8/site-packages/pandas/compat/__init__.py", line 15, in <module>
from pandas.compat.numpy import (
File "/Users/olespaarmann/mambaforge/envs/diversity_scraper/lib/python3.8/site-packages/pandas/compat/numpy/__init__.py", line 7, in <module>
from pandas.util.version import Version
File "/Users/olespaarmann/mambaforge/envs/diversity_scraper/lib/python3.8/site-packages/pandas/util/__init__.py", line 1, in <module>
from pandas.util._decorators import ( # noqa
File "/Users/olespaarmann/mambaforge/envs/diversity_scraper/lib/python3.8/site-packages/pandas/util/_decorators.py", line 14, in <module>
from pandas._libs.properties import cache_readonly # noqa
File "/Users/olespaarmann/mambaforge/envs/diversity_scraper/lib/python3.8/site-packages/pandas/_libs/__init__.py", line 13, in <module>
from pandas._libs.interval import Interval
File "pandas/_libs/interval.pyx", line 1, in init pandas._libs.interval
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject
The solution here is to just ignore the dependency issues and manually install a newer version of numpy. It doesn't work when I set the numpy version in my requirements.txt because this throws a dependency error:
ERROR: Cannot install numpy>=1.20.0 and tensorflow==2.6.0 because these package versions have conflicting dependencies.
The conflict is caused by:
The user requested numpy>=1.20.0
tensorflow 2.6.0 depends on numpy~=1.19.2
So I just installed it with python -m pip install numpy==1.20.0. And now everything seems to work.
In my Conda environment, when I run pip show MetPy, my first and last two lines are:
Name: MetPy
Version: 1.0
...
Requires: scipy, matplotlib, pandas, pyproj, pooch, importlib-resources, traitlets, importlib-metadata, numpy, pint, xarray
Required-by:
When I run pip show pint, my first and last two lines are:
Name: Pint
Version: 0.16.1
...
Requires: packaging, importlib-metadata
Required-by: MetPy
These should be the latest versions of these packages. Yet, when I try to do...
import metpy.calc as mpcalc
...I get the following error:
Traceback (most recent call last):
File "redacted.py", line 17, in <module>
import metpy.calc as mpcalc
File "~/anaconda3/envs/environment/lib/python3.7/site-packages/metpy/calc/__init__.py", line 7, in <module>
from .cross_sections import * # noqa: F403
File "~/anaconda3/envs/environment/lib/python3.7/site-packages/metpy/calc/cross_sections.py", line 14, in <module>
from .tools import first_derivative
File "~/anaconda3/envs/environment/lib/python3.7/site-packages/metpy/calc/tools.py", line 106, in <module>
def find_intersections(x, a, b, direction='all', log_x=False):
File "~/anaconda3/envs/environment/lib/python3.7/site-packages/pint/registry_helpers.py", line 248, in decorator
% (func.__name__, count_params, len(args))
TypeError: find_intersections takes 5 parameters, but 3 units were passed
This makes me think I'm missing something with my package updates. Is there another dependency I'm missing?
It appears likely that you might not have pip installed within your conda environment or that you are running pip from somewhere outside your conda environment, and so pip show might be misleading you. Check your versions of MetPy and Pint within your conda environment with conda list, as this should be a version conflict error between older versions of MetPy (<=0.11.1) and newer versions of Pint (>0.9).
conda install -c conda-forge metpy==1.0 should get your conda environment caught up to MetPy 1.0.
I usually work with the Jupyter Notebook Interface when programming Python but recently I installed bioservices through pip (Bioservices) and when I tried to open the Jupyter Notebook I get the following RunTime error:
~$ jupyter notebook
Traceback (most recent call last):
File "/usr/local/bin/jupyter-notebook", line 7, in <module>
from notebook.notebookapp import main
File "/usr/local/lib/python2.7/dist-packages/notebook/notebookapp.py", line 60, in <module>
from .services.contents.manager import ContentsManager
File "/usr/local/lib/python2.7/dist-packages/notebook/services/contents/manager.py", line 16, in <module>
from nbformat import sign, validate, ValidationError
File "/usr/local/lib/python2.7/dist-packages/nbformat/__init__.py", line 33, in <module>
from .validator import validate, ValidationError
File "/usr/local/lib/python2.7/dist-packages/nbformat/validator.py", line 12, in <module>
from jsonschema import ValidationError
File "/usr/local/lib/python2.7/dist-packages/jsonschema/__init__.py", line 18, in <module>
from jsonschema.validators import (
File "/usr/local/lib/python2.7/dist-packages/jsonschema/validators.py", line 8, in <module>
import requests
File "/home/bioinfo/.local/lib/python2.7/site-packages/requests/__init__.py", line 74, in <module>
raise RuntimeError('Requests dependency \'chardet\' must be version >= 3.0.2, < 3.1.0!')
RuntimeError: Requests dependency 'chardet' must be version >= 3.0.2, < 3.1.0!
P.S: I uninstalled bioservices and it did not solve the error! Tried to reinstall chardet but it give the next output:
~$ pip install chardet==3.0.2
Collecting chardet==3.0.2
Using cached chardet-3.0.2-py2.py3-none-any.whl
Installing collected packages: chardet
Successfully installed chardet-2.3.0
This looks like a broken dependency. Have you tried installing the correct version of the chardet package, e.g.
pip install chardet==3.0.2
Of course here I'm assuming you have pip installed. Otherwise you're stuck with what your system ships. In that case, I would advise installing pip or any alternative way to control you python installation on a finer level.
Apparently you have a package named chardet required somewhere, but the version of this module is deprecated. Try to update chardet with pip upgrade chardet or uninstall and reinstall it.
$ pip uninstall chardet
$ pip install chardet
I have also same error. after trying all it doesn't work for me.
so I simply uninstall it:
pip uninstall jupyter
Then again install jupyter notebook
(it doesn't remove your installed library, simply uninstall jupyter) let's try
it has already claimed that I have either installed or upgraded six module
C:\Users\floatSD\Downloads\setuptools-34.3.1\setuptools-34.3.1>pip install --upgrade six
Requirement already up-to-date: six in c:\users\floatsd\anaconda3\lib\site-packages
but it shows error run the easy_install.py
C:\Users\floatSD\Downloads\setuptools-34.3.1\setuptools-34.3.1>python easy_install.py
and it returns:
Traceback (most recent call last):
File "easy_install.py", line 4, in <module>
from setuptools.command.easy_install import main
File "C:\Users\floatSD\Downloads\setuptools-34.3.1\setuptools-34.3.1\setuptools\__init__.py", line 10, in <module>
from six.moves import filter, map
ImportError: No module named six.moves
p.s. my pip version is 9.0.1
I tried uninstall and install six again, but still doesn't work
C:\Users\floatSD\Downloads\setuptools-34.3.1\setuptools-34.3.1>pip uninstall six
DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project.
Uninstalling six-1.10.0:
c:\users\floatsd\anaconda3\lib\site-packages\six-1.10.0-py3.5.egg-info
Proceed (y/n)? y
Successfully uninstalled six-1.10.0
C:\Users\floatSD\Downloads\setuptools-34.3.1\setuptools-34.3.1>pip install six
Collecting six
Downloading six-1.10.0-py2.py3-none-any.whl
Installing collected packages: six
Successfully installed six-1.10.0
C:\Users\floatSD\Downloads\setuptools-34.3.1\setuptools-34.3.1>python easy_install.py
Traceback (most recent call last):
File "easy_install.py", line 4, in <module>
from setuptools.command.easy_install import main
File "C:\Users\floatSD\Downloads\setuptools-34.3.1\setuptools-34.3.1\setuptools\__init__.py", line 10, in <module>
from six.moves import filter, map
ImportError: No module named six.moves