I am part of a Gitlab python3 project where we are trying to install continuous integration thanks to the file .gitlab-ci.yml.
I am trying to install python3 and all the modules that we need, in order to execute a python test script.
I succeeded in installing python3 thanks to apk with the following command.
- apt-get -qq update && apt-get -qq install -y python3
I first need to install pandas, this is working well.
Next, I am trying to install the module matplotlib.pyplot, but it seems impossible, this command does not work:
- pip3 install matplotlib.pyplot
Collecting matplotlib.pyplot
Could not find a version that satisfies the requirement matplotlib.pyplot
(from versions: )
No matching distribution found for matplotlib.pyplot
Any idea on how to fix this issue? Thank you
Related
I am using Python 3.9.13. I installed scikit-learn from the terminal:
pip install scikit-learn
Then I tried to download the mnist dataset using fetch_openml:
from sklearn.datasets import fetch_openml
raw_data = fetch_openml('mnist_784')
That gave me a long error message ending with:
fetch_openml with as_frame=True requires pandas.
However, I had pandas installed. So I looked more deeply inside the error message and I found that the exception causing that error was this:
ModuleNotFoundError: No module named '_bz2'
I looked around and found a solution in this thread.
I only had to add another step to that solution.
After installing libbz2-dev I only had _bz2.cpython-38-x86_64-linux-gnu.so on my computer which is used for python 3.8.x so it did not work with my version of python.
I changed the file's name to _bz2.cpython-39-x86_64-linux-gnu.so and it worked after that.
sudo apt-get install libbz2-dev
sudo cp /usr/lib/python3.8/lib-dynload/_bz2.cpython-38-x86_64-linux-gnu.so /usr/local/lib/python3.9/
sudo mv /usr/local/lib/python3.9/_bz2.cpython-38-x86_64-linux-gnu.so /usr/local/lib/python3.9/_bz2.cpython-39-x86_64-linux-gnu.so
I had a similar issue with _lzma library when I wanted to import torchvision.
The issue was solved with running below lines in the terminal:
sudo apt install liblzma-dev
sudo cp /usr/lib/python3.8/lib-dynload/_lzma.cpython-38-x86_64-linux-gnu.so /usr/local/lib/python3.9/
sudo mv /usr/local/lib/python3.9/_lzma.cpython-38-x86_64-linux-gnu.so /usr/local/lib/python3.9/_lzma.cpython-39-x86_64-linux-gnu.so
I'm trying to build a python app via docker, but it fails to import numpy even though I've installed the appropriate package via apt. As an example of the dockerfile reduced to only what's important here:
FROM python:3
RUN apt-get update \
&& apt-get install python3-numpy -y
RUN python3 -c "import numpy; print(numpy.__version__)"
Attempting to build that dockerfile results in the error ModuleNotFoundError: No module named 'numpy'.
I am able to get this working if I use pip to install numpy, but I was hoping to get it working with the apt-get package instead. Why isn't this working the way I would expect it to?
The problem is that you have two Pythons installed:
The image comes with python in /usr/local/bin.
When you install python3-numpy, that install python3 package from Debian, which ends up with /usr/bin/python.
When you run your code at the end you're likely using the version from /usr/local/bin, but NumPy was installed for the version in /usr/bin.
Solution: Install NumPy using pip, e.g. pip install numpy, instead of using apt.
Long version, with other ways you can get import errors: https://pythonspeed.com/articles/importerror-docker/
The problem is with python environments, not with docker. The apt-get installed numpy is not in the same environment as the python installation. Moreover, the dependencies should be stored in a requirements.txt file, which should then be installed through pip. python -m pip can be used to ensure that the pip command is in the same environment as the python installation.
I have a Docker container running from tensrflow with Jupyter (Python 3 Kernel) image: erroneousboat/tensorflow-python3-jupyter
This works great and I can access the jupyter notebook from
http://DOCKER_IP:8888
My only issue is that pandas library is not installed. So, I tried to install it on my own. I opened up the docker quickstart terminal and ran:
docker exec CONTAINER_ID apt-get update
docker exec CONTAINER_ID apt-get install -y python3-pandas
The installation succeeds, and yet I still get the ImportError: No module named 'pandas' when I try to import pandas in the jupyter notebook, like so:
import pandas as pd
I also tried installing pandas to the image rather than just my container by:
docker run -it erroneousboat/tensorflow-python3-jupyter /bin/bash
apt-get update
apt-get install -y python3-pandas
exit
Still, in my jupyter notebook, pandas is not recognized. How can I fix this? Thank you!
pip install pandas will install the latest version of pandas for you.
Based on your tags python-3.x, I assumed pip belongs to your Python3 version, if you have multiple python versions installed, make sure you have the correct pip.
The code line:
import matplotlib
The error:
ImportError: No module named 'matplotlib'
The problem:
which python3.4 % /usr/bin/python3.4
Where is matplotlib installed?
sudo find /usr | grep matplotlib % /usr/lib/pymodules/python2.7/matplotlib/...
Some considerations:
OS: Linux Mint 17.2
I need to use Python 3.4
Solutions:
import sys sys.path.append('/usr/lib/pymodules/python2.7/') (Not happy with this one).
Using pip3 install matplotlib or sudo pip3 install matplotlib (Recieving errors, and i dont like this one too).
Using sudo apt-get install python-matplotlib (May be the perfect one, but installs matplotlib in python2.7 directory).
How can i make matplotlib work for python3?
Thanks
Just when i was about to make the question realized that instead of typing
sudo apt-get install python-matplotlib
I needed to type
sudo apt-get install python3-matplotlib
I just upgraded to python3 on Fedora, and was trying to import pylab. But instead I got an error
ImportError: No module named 'pylab'
After some research I found some information about installing a package matplotlib-py3k to make it work. However, the link to the page is down! Maybe there is a yum install package I can use to simply install pylab to work with python3?
The package for python2.x is installed and working.
Try yum install python-matplotlib. If I am mistaken, then you can try from the source.
From the matplotlib website...
If you are on Fedora/RedHat, you can get all the dependencies required
to build matplotlib by first installing yum-builddep and then running:
su -c "yum-builddep python-matplotlib" This does not build matplotlib,
but it does get all of the build dependencies, which will make
building from source easier.
Then you can use git clone git#github.com:matplotlib/matplotlib.git to git matplotlib and then install with cd matplotlib and python setup.py install.
You need to install matplotlib for python3 by performing:
yum install python3-matplotlib