How to get a clean Python environment on Zorin :)

Hi, I understand that, with orin OS 17.2 Pro and X11,
you don't have a Python environment. Only the Python language.

I tried to install some applications:

  • pandas,
  • numpy,
  • matplotlib...

Not easy, but it seems that pandas and numpy work.

For matplotlib,
I have still an issue with "import matplotlib.pyplot as plt"
or `"import matplotlib as plt"

On Jupyter Notebook, I have this message:

1 | import matplotlib.pyplot as plt

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/tmp/ipykernel_31662/322768712.py in <module>
----> 1 import matplotlib.pyplot as plt

~/.local/lib/python3.10/site-packages/matplotlib/__init__.py in <module>
    996 
    997 rcParamsDefault = _rc_params_in_file(
--> 998     cbook._get_data_path("matplotlibrc"),
    999     # Strip leading comment.
   1000     transform=lambda line: line[1:] if line.startswith("#") else line,

/usr/lib/python3/dist-packages/matplotlib/cbook/__init__.py in _get_data_path(*args)
    516     ``*args`` specify a path relative to the base data path.
    517     """
--> 518     return Path(matplotlib.get_data_path(), *args)
    519 
    520 

AttributeError: module 'matplotlib' has no attribute 'get_data_path'

Let me ask you,
What will be a clean installation of python and pip?

No need of Anaconda :).

Thank you for your feedback.

José

The last command for matplotlib installation...

It seems that there is a strong connection with "numpy" :).

See this message:

Defaulting to user installation because normal site-packages is not writeable

jrd10@jrd10-G3-3500:~$ pip install numpy --upgrade --ignore-installed
Defaulting to user installation because normal site-packages is not writeable
Collecting numpy
  Downloading numpy-2.2.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 16.4/16.4 MB 32.5 MB/s eta 0:00:00
Installing collected packages: numpy
Successfully installed numpy-2.2.4

----

jrd10@jrd10-G3-3500:~$ pip install matplotlib --upgrade --ignore-installed
Defaulting to user installation because normal site-packages is not writeable
Collecting matplotlib
  Downloading matplotlib-3.10.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (8.6 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 8.6/8.6 MB 34.1 MB/s eta 0:00:00
Collecting fonttools>=4.22.0
  Downloading fonttools-4.56.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.6 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.6/4.6 MB 31.2 MB/s eta 0:00:00
Collecting packaging>=20.0
  Downloading packaging-24.2-py3-none-any.whl (65 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 65.5/65.5 KB 17.4 MB/s eta 0:00:00
Collecting numpy>=1.23
  Using cached numpy-2.2.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (16.4 MB)
Collecting pillow>=8
  Downloading pillow-11.1.0-cp310-cp310-manylinux_2_28_x86_64.whl (4.5 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.5/4.5 MB 36.0 MB/s eta 0:00:00
Collecting pyparsing>=2.3.1
  Downloading pyparsing-3.2.1-py3-none-any.whl (107 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 107.7/107.7 KB 21.2 MB/s eta 0:00:00
Collecting python-dateutil>=2.7
  Downloading python_dateutil-2.9.0.post0-py2.py3-none-any.whl (229 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 229.9/229.9 KB 30.9 MB/s eta 0:00:00
Collecting cycler>=0.10
  Downloading cycler-0.12.1-py3-none-any.whl (8.3 kB)
Collecting kiwisolver>=1.3.1
  Downloading kiwisolver-1.4.8-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl (1.6 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.6/1.6 MB 30.3 MB/s eta 0:00:00
Collecting contourpy>=1.0.1
  Downloading contourpy-1.3.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (324 kB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 325.0/325.0 KB 26.6 MB/s eta 0:00:00
Collecting six>=1.5
  Downloading six-1.17.0-py2.py3-none-any.whl (11 kB)
Installing collected packages: six, pyparsing, pillow, packaging, numpy, kiwisolver, fonttools, cycler, python-dateutil, contourpy, matplotlib
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
mastodon-py 1.8.0 requires python-magic, which is not installed.
Successfully installed contourpy-1.3.1 cycler-0.12.1 fonttools-4.56.0 kiwisolver-1.4.8 matplotlib-3.10.1 numpy-2.2.4 packaging-24.2 pillow-11.1.0 pyparsing-3.2.1 python-dateutil-2.9.0.post0 six-1.17.0
jrd10@jrd10-G3-3500:~$ 

Python is available regardless of the window display server (X11 or Wayland). A Python virtual environment does not come by default. It wouldn't make sense to, either: you create and destroy them as needed, and you have to enable them explicitly on each shell session anyway.

You don't have to use a virtual environment if you don't want to, it's just a way to get things organized.

  1. Install the python3-venv package:

    sudo apt install python3-venv
    
  2. Create a new virtual environment:

    python3 -m venv my_new_environment
    

    The name of the environment is entirely up to you. You'd often see online that people prefix it with a dot . to make it a hidden directory.

  3. Activate and deactivate it using:

    source path/to/my_new_environment/bin/activate
    

    Notice the prompt changes slightly to show the name of your environment. You can start running commands from there like installing anything that you need:

    (my_new_environment) zenzen@zenzen:~$ pip3 install numpy

    When you're done, you can run:

    deactivate
    
  4. A tip: create an alias for python3 and pip3 since it's quite annoying to have to type that all the time. In your ~/.bashrc add this at the bottom:

     alias python='python3'
     alias pip='pip3'
    

I haven't installed any of those libraries myself so I can't say what's the best way to do so. But you can just create a new environment and start over, since the dependencies will be kept independent from the rest of the system, and other environments anyway.

1 Like

Thank you for this clear and fast feedback.

[update] Ok, it works

See history post if you want to know more :slight_smile:
I didn't use the "path/to"

jrd10@jrd10-G3-3500:/$ sudo python -m venv jrd10
[sudo] password for jrd10:       
sudo: python: command not found
jrd10@jrd10-G3-3500:/$ sudo python3 -m venv jrd10
jrd10@jrd10-G3-3500:/$ 
jrd10@jrd10-G3-3500:/$ source jrd10/bin/activate
=> (jrd10) jrd10@jrd10-G3-3500:/$ 

Thank you again.

José

This path was an example instructional path that Zenzen used.
You will need to replace that with the actual path to your destination on your computer.

2 Likes

[UPDATE :slight_smile: ] See below my previous message...

It does not work completely

This may be due to multiple versions of Matplotlib being installed (e.g. as a system package and as a pip package). As a result, the 3D projection is not available.
warnings.warn("Unable to import Axes3D. This may be due to multiple versions of "

How to uninstall the application out of my "jrd10" environment?

Error message in Jupyter Notebook :slight_smile:

# From : https://openaq.org/ ; # http://dhhagan.github.io/py-openaq/index.html
# https://github.com/pandas-dev/pandas/blob/main/doc/data/air_quality_no2.csv
import pandas as pd
import matplotlib.pyplot as plt
url_air_quality_csv = "https://github.com/pandas-dev/pandas/blob/main/doc/data/air_quality_no2.csv"
df_air_quality = pd.read_csv("url_air_quality_csv")


/home/jrd10/.local/lib/python3.10/site-packages/matplotlib/projections/__init__.py:63: UserWarning: Unable to import Axes3D. This may be due to multiple versions of Matplotlib being installed (e.g. as a system package and as a pip package). As a result, the 3D projection is not available.
  warnings.warn("Unable to import Axes3D. This may be due to multiple versions of "

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
/tmp/ipykernel_13583/1921359942.py in <module>
      7 url_air_quality_csv = "https://github.com/pandas-dev/pandas/blob/main/doc/data/air_quality_no2.csv"
      8 
----> 9 df_air_quality = pd.read_csv("url_air_quality_csv")
     10 

/usr/local/lib/python3.10/dist-packages/pandas/io/parsers/readers.py in read_csv(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, date_format, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options, dtype_backend)
   1024     kwds.update(kwds_defaults)
   1025 
-> 1026     return _read(filepath_or_buffer, kwds)
   1027 
   1028 

/usr/local/lib/python3.10/dist-packages/pandas/io/parsers/readers.py in _read(filepath_or_buffer, kwds)
    618 
    619     # Create the parser.
--> 620     parser = TextFileReader(filepath_or_buffer, **kwds)
    621 
    622     if chunksize or iterator:

/usr/local/lib/python3.10/dist-packages/pandas/io/parsers/readers.py in __init__(self, f, engine, **kwds)
   1618 
   1619         self.handles: IOHandles | None = None
-> 1620         self._engine = self._make_engine(f, self.engine)
   1621 
   1622     def close(self) -> None:

/usr/local/lib/python3.10/dist-packages/pandas/io/parsers/readers.py in _make_engine(self, f, engine)
   1878                 if "b" not in mode:
   1879                     mode += "b"
-> 1880             self.handles = get_handle(
   1881                 f,
   1882                 mode,

/usr/local/lib/python3.10/dist-packages/pandas/io/common.py in get_handle(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)
    871         if ioargs.encoding and "b" not in ioargs.mode:
    872             # Encoding
--> 873             handle = open(
    874                 handle,
    875                 ioargs.mode,

FileNotFoundError: [Errno 2] No such file or directory: 'url_air_quality_csv'



[update...]

No, it works :slight_smile:
Just, before using the matplotlib library, we have to deactivate this environment :slight_smile:

Thank you for your help :slight_smile:

1 Like

A way?

  • pip3 list
  • and pip3 list --local
jrd10@jrd10-G3-3500:~$ pip3 list
Package                 Version
----------------------- --------------------
appdirs                 1.4.4
apturl                  0.5.2
argon2-cffi             21.1.0
attrs                   21.2.0
Babel                   2.8.0
backcall                0.2.0
bcrypt                  3.2.0
beautifulsoup4          4.10.0
beniget                 0.4.1
bleach                  4.1.0
blinker                 1.4
blurhash                1.1.4
Brlapi                  0.8.3
Brotli                  1.0.9
certifi                 2020.6.20
cffi                    1.15.1
chardet                 4.0.0
click                   8.0.3
colorama                0.4.4
command-not-found       0.3
contourpy               1.3.1
cryptography            3.4.8
cupshelpers             1.0
cycler                  0.12.1
dbus-python             1.2.18
decorator               4.4.2
defer                   1.0.6
defusedxml              0.7.1
distro                  1.7.0
distro-info             1.1+ubuntu0.2
duplicity               0.8.21
entrypoints             0.4
et_xmlfile              2.0.0
fasteners               0.14.1
folder-color            0.2.0
fonttools               4.56.0
fs                      2.4.12
future                  0.18.2
gast                    0.5.2
html5lib                1.1
httplib2                0.20.2
icoextract              0.1.2
idna                    3.3
importlib-metadata      4.6.4
ipykernel               6.7.0
ipython                 7.31.1
ipython_genutils        0.2.0
ipywidgets              6.0.0
jedi                    0.18.0
jeepney                 0.7.1
Jinja2                  3.0.3
jsonschema              3.2.0
jupyter-client          7.1.2
jupyter-core            4.9.1
jupyterlab-pygments     0.1.2
keyring                 23.5.0
kiwisolver              1.4.8
language-selector       0.1
launchpadlib            1.10.16
lazr.restfulclient      0.14.4
lazr.uri                1.0.6
lockfile                0.12.2
louis                   3.20.0
lxml                    4.8.0
lz4                     3.1.3+dfsg
macaroonbakery          1.3.1
Mako                    1.1.3
MarkupSafe              2.0.1
Mastodon.py             1.8.0
matplotlib              3.10.1
matplotlib-inline       0.1.3
monotonic               1.6
more-itertools          8.10.0
mpmath                  0.0.0
nbclient                0.5.6
nbconvert               6.4.0
nbformat                5.1.3
nest-asyncio            1.5.4
netifaces               0.11.0
notebook                6.4.8
numpy                   2.2.4
oauthlib                3.2.0
olefile                 0.46
openpyxl                3.1.5
packaging               24.2
pandas                  2.2.3
pandocfilters           1.5.0
paramiko                2.9.3
parso                   0.8.1
pefile                  2021.9.3
pexpect                 4.8.0
pickleshare             0.7.5
pillow                  11.1.0
pip                     22.0.2
ply                     3.11
prometheus-client       0.9.0
prompt-toolkit          3.0.28
protobuf                3.12.4
psutil                  5.9.0
ptyprocess              0.7.0
py                      1.10.0
pycairo                 1.20.1
pycparser               2.21
pycups                  2.0.1
pyelftools              0.27
Pygments                2.11.2
PyGObject               3.42.1
PyJWT                   2.3.0
pymacaroons             0.13.0
PyNaCl                  1.5.0
pyparsing               3.2.1
pyRFC3339               1.1
pyrsistent              0.18.1
python-apt              2.4.0-ubuntu4-zorin1
python-dateutil         2.9.0.post0
python-debian           0.1.43+ubuntu1.1
pythran                 0.10.0
pytz                    2022.1
pyxdg                   0.27
PyYAML                  5.4.1
pyzmq                   22.3.0
reportlab               3.6.8
requests                2.25.1
scipy                   1.8.0
screen-resolution-extra 0.0.0
SecretStorage           3.3.1
Send2Trash              1.8.1b0
setuptools              59.6.0
six                     1.17.0
soupsieve               2.3.1
srt                     3.5.2
sympy                   1.9
terminado               0.13.1
testpath                0.5.0
tornado                 6.1
tqdm                    4.64.1
traitlets               5.1.1
tzdata                  2025.1
ubuntu-drivers-common   0.0.0
ufoLib2                 0.13.1
ufw                     0.36.1
unattended-upgrades     0.1
unicodedata2            14.0.0
urllib3                 1.26.5
vosk                    0.3.45
wadllib                 1.3.6
wcwidth                 0.2.5
webencodings            0.5.1
websockets              10.4
wheel                   0.37.1
widgetsnbextension      2.0.0
xdg                     5
xkit                    0.0.0
zipp                    1.0.0
zorin-appearance        5.3
zorin-connect           1.2
zorin-exec-guard        1.5
jrd10@jrd10-G3-3500:~$ 

jrd10@jrd10-G3-3500:~$ pip3 list --local
Package         Version
--------------- -----------
blurhash        1.1.4
cffi            1.15.1
contourpy       1.3.1
cycler          0.12.1
et_xmlfile      2.0.0
fonttools       4.56.0
kiwisolver      1.4.8
Mastodon.py     1.8.0
matplotlib      3.10.1
numpy           2.2.4
openpyxl        3.1.5
packaging       24.2
pandas          2.2.3
pillow          11.1.0
pycparser       2.21
pyparsing       3.2.1
python-dateutil 2.9.0.post0
six             1.17.0
srt             3.5.2
tqdm            4.64.1
tzdata          2025.1
vosk            0.3.45
websockets      10.4
jrd10@jrd10-G3-3500:~$ 

You clearly have it installed using PIP.

You can check if you installed with APT too:

apt list python3-matplotlib

If it shows an installed version; then you have both installed. However, this gets tricky.
Either installation method will retain the same dependencies - so if you remove the APT version; it may remove the dependencies that PIP version is using.
If this was me, I would Remove Both Packages, completely. Then install fresh and full using One Method.

1 Like

Hi Aravisian,
Yes, it can be tricky.
In case of troubles, I prefer uninstalling all the present libraries and to install again pip and Python3 libraries with it :).

  1. Remove ok with

sudo apt remove python3-matplotlib

  1. Still here

  2. Autoremove

  3. Still here?!

It's ok, I will review that in case I have again this issue :slight_smile:

Thank you for your time

José

jrd10@jrd10-G3-3500:~$ sudo apt remove python3-matplotlib
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  fonts-lyx libboost-dev libboost1.74-dev liblbfgsb0 libopenblas-dev
  libopenblas-pthread-dev libopenblas0 libxsimd-dev python-matplotlib-data
  python3-appdirs python3-beniget python3-brotli python3-cycler
  python3-fonttools python3-fs python3-gast python3-kiwisolver python3-lz4
  python3-mpmath python3-numpy python3-ply python3-pythran python3-scipy
  python3-sympy python3-ufolib2 python3-unicodedata2 unicode-data
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
  python3-matplotlib
0 upgraded, 0 newly installed, 1 to remove and 26 not upgraded.
After this operation, 19,3 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 330234 files and directories currently installed.)
Removing python3-matplotlib (3.5.1-2build1) ...
jrd10@jrd10-G3-3500:~$ 

jrd10@jrd10-G3-3500:~$ apt list python3-matplotlib
Listing... Done
python3-matplotlib/jammy 3.5.1-2build1 amd64
jrd10@jrd10-G3-3500:~$ 

rd10@jrd10-G3-3500:~$ sudo apt autoremove
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  fonts-lyx libboost-dev libboost1.74-dev liblbfgsb0 libopenblas-dev
  libopenblas-pthread-dev libopenblas0 libxsimd-dev python-matplotlib-data
  python3-appdirs python3-beniget python3-brotli python3-cycler
  python3-fonttools python3-fs python3-gast python3-kiwisolver python3-lz4
  python3-mpmath python3-numpy python3-ply python3-pythran python3-scipy
  python3-sympy python3-ufolib2 python3-unicodedata2 unicode-data
0 upgraded, 0 newly installed, 27 to remove and 26 not upgraded.
After this operation, 374 MB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 329778 files and directories currently installed.)
Removing python-matplotlib-data (3.5.1-2build1) ...
Removing fonts-lyx (2.3.6-1) ...
dpkg: warning: while removing fonts-lyx, directory '/usr/share/fonts/truetype/ly
x' not empty so not removed
Removing libopenblas-dev:amd64 (0.3.20+ds-1) ...
Removing libopenblas0:amd64 (0.3.20+ds-1) ...
Removing python3-cycler (0.11.0-1) ...
Removing python3-kiwisolver (1.3.2-1build1) ...
Removing python3-ufolib2 (0.13.1+dfsg1-1) ...
Removing python3-fonttools (4.29.1-2build1) ...
Removing python3-scipy (1.8.0-1exp2ubuntu1) ...
Removing python3-pythran (0.10.0+ds2-1) ...
Removing libboost-dev:amd64 (1.74.0.3ubuntu7) ...
Removing libboost1.74-dev:amd64 (1.74.0-14ubuntu3) ...
Removing liblbfgsb0:amd64 (3.0+dfsg.3-10) ...
Removing libopenblas-pthread-dev:amd64 (0.3.20+ds-1) ...
Removing libxsimd-dev:amd64 (7.6.0-2) ...
Removing python3-fs (2.4.12-1) ...
Removing python3-appdirs (1.4.4-2) ...
Removing python3-beniget (0.4.1-2) ...
Removing python3-brotli (1.0.9-2build6) ...
Removing python3-gast (0.5.2-2) ...
Removing python3-lz4 (3.1.3+dfsg-1build3) ...
Removing python3-sympy (1.9-1) ...
Removing python3-mpmath (1.2.1-2) ...
Removing python3-numpy (1:1.21.5-1ubuntu22.04.1) ...
Removing python3-ply (3.11-5) ...
Removing python3-unicodedata2 (14.0.0+ds-8) ...
Removing unicode-data (14.0.0-1.1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.9) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for fontconfig (2.13.1-4.2ubuntu5) ...
jrd10@jrd10-G3-3500:~$ 
jrd10@jrd10-G3-3500:~$ 
jrd10@jrd10-G3-3500:~$ apt list python3-matplotlib
Listing... Done
python3-matplotlib/jammy 3.5.1-2build1 amd64
jrd10@jrd10-G3-3500:~$ 
jrd10@jrd10-G3-3500:~$ pip3 list --local
Package         Version
--------------- -----------
blurhash        1.1.4
cffi            1.15.1
contourpy       1.3.1
cycler          0.12.1
et_xmlfile      2.0.0
fonttools       4.56.0
kiwisolver      1.4.8
Mastodon.py     1.8.0
matplotlib      3.10.1
numpy           2.2.4
openpyxl        3.1.5
packaging       24.2
pandas          2.2.3
pillow          11.1.0
pycparser       2.21
pyparsing       3.2.1
python-dateutil 2.9.0.post0
six             1.17.0
srt             3.5.2
tqdm            4.64.1
tzdata          2025.1
vosk            0.3.45
websockets      10.4
jrd10@jrd10-G3-3500:~$ 

Jupyter Notebook seems to be ok.

Now remove using PIP...

Then check if anything is leftover installed.