[go: up one dir, main page]

0% found this document useful (0 votes)
13 views2 pages

Python Tips

Uploaded by

segis39186
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

Python Tips

Uploaded by

segis39186
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

Python tips on Ubuntu and Windows

Unsure of which python version is in use

Although a python executable might be in the PATH, other versions might be installed and used by
default by some applications, e.g. double-check which one is called when using an IDE such as Visual
Studio, PyCharm, Spyder, etc. To install packages specifically for that version, open a terminal and
call python with its full path e.g.
C:\Python310\python.exe -m pip install opencv-contrib-python
/usr/local/bin/python3 -m pip install opencv-contrib-python

For Ubuntu, Python executable might be in the PATH usually as a link inside /usr/bin, check where
with which python3 and then ls -l /the/path/that/was/returned. For Windows it can vary quite a
lot, check with where python. Same for pip executable.

sudo apt install python3-xxx vs sudo pip install xxx vs pip install xxx

pip with sudo: installed in /usr/lib. Warning: some recent OS or Python version might not allow any
more to use directly pip with sudo, as suggested by the error message you might need to add --
break-system-packages parameter.
pip without sudo: installed in ~/.local/lib (for current user)
With apt: version officially supported for the specific Ubuntu version (if any)
With pip: latest version is installed with pip install --upgrade xxx or with just pip install xxx in the
case where the package is not already installed (if already installed, it might not be changed unless
there are specific version requirements from dependent packages) or specific version with pip install
xxx==1.0.0.0

On Windows there is no real equivalent of apt. The equivalent of sudo is when a program (e.g. the
Command Prompt) that runs python.exe or pip.exe is explicitly run as Administrator (a User Account
Control prompt should have appeared at some point), in that case the packages will be installed in
the folder where Python is supposedly installed for all users (e.g. C:\Python310, C:\Program Files\
Python310), otherwise it should be in %USERPROFILE%\AppData\Roaming\Python\Python310\
site-packages. The behavior might be more complicated if some dependencies were already
installed as a standard user…

Error when installing some packages with pip

Some packages might need a C/C++ compiler available during installation to be fully installed
successfully, use sudo apt install build-essential to install default gcc/g++ for Ubuntu, for Windows
you might want to install Visual Studio (see e.g.
https://www.ensta-bretagne.fr/lebars/Share/setup_vs_opencv.pdf) or other compiler, check the
package website…

PyCharm

If using Matplotlib, you might need to toggle Settings > Tools > Python Plot > Show plots in tool
window (previously Settings > Tools > Python Scientific > Show plots in tool window) option...
Note that right-clicking and choosing Run file in Python console shows the variables view, and
commands can be entered in the Python console…

Spyder

If using Matplotlib, you might need to change Tools > Preferences > IPython console > Graphics >
Graphics backend to Automatic option and relaunch Spyder...

Visual Studio 2022

It is not as easy as in previous versions to quicky run a Python file outside a project, see the issue
https://developercommunity.visualstudio.com/t/Start-withwithout-Debugging-right-click/10390676
for possible workarounds and their drawbacks.

You might also like