Python Runtime Environments: Unterschied zwischen den Versionen

Aus MattWiki
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
 
(10 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
This article tries to bring structure into the different runtime environments for Python for running python programs or Jupyter Notebooks and their advantages and drawbacks:
This article tries to bring structure into the different runtime environments for Python for running python programs or Jupyter Notebooks and their advantages and drawbacks.


= '''<big><u>''This site is a major work in progress''</u></big>''' =
'''<big><u>''This site is a major work in progress''</u></big>'''
 
== Management of Environments ==
pip list
pip install


== Linux Environments ==
== Linux Environments ==


=== Debian ===
=== Debian ===
Managed by distribution - Available Packages in Aptitude
Python runtine environment on debian is managed by Debian distribution. This means that you can not install additional packages with <code>pip install <package></code>. If you try you get the following output:
matt@mypc:~$ pip install matplotlib
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.
    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.
    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.
    See /usr/share/doc/python3.11/README.venv for more information.
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
There are two options to proceed:
 
=== Debian Managed Packages ===
Try and find needed modules in the packages provided by Debian distribution:
apt-get install <package>    # Install package
aptitude                    # Interface for searching and installing available packages


=== Virtual Environment (venv) ===
=== Virtual Environment (venv) ===
pip
Install additional virtual environment as described in the message above, i.e.:
python3 -m venv ~/venv/finpy
Now either issue commands against that environments as follows:
~/venv/finpy/bin/python script1.py
~/venv/finpy/bin/pip install <package>
For further reading about pip see [[PIP Cheat Sheet]]
 
A more comfortable option is to switch to the environment sepcified by its path:
source ~/venv/finpy/bin/activate
Example:
matt@mypc:~$ source ~/venv/finpy/bin/activate
(finpy) matt@mypc:~$
All subsequent commands will be executed in the context of the active environment, which is now listed in parentheses.
 
In order to leave the virtual environment again:
matt@mypc:~$ deactivate


== Windows Environments ==
== Windows Environments ==
Zeile 20: Zeile 58:


=== Miniconda ===
=== Miniconda ===
pip
Further reading: [[Miniconda Cheat Sheet]]
 
For handling PIP within Miniconda see [[PIP Cheat Sheet]]


=== Known Issues ===
=== Known Issues ===
Zeile 26: Zeile 66:


* yfinance.download seems not to work properly on Windows
* yfinance.download seems not to work properly on Windows
== Jupyter Notebooks ==
=== Standalone ===
=== In Visual Studio Code ===
[[Kategorie:Python]]
[[Kategorie:Python]]
[[Kategorie:Terminal]]

Aktuelle Version vom 20. Juli 2025, 12:39 Uhr

This article tries to bring structure into the different runtime environments for Python for running python programs or Jupyter Notebooks and their advantages and drawbacks.

This site is a major work in progress

Linux Environments

Debian

Python runtine environment on debian is managed by Debian distribution. This means that you can not install additional packages with pip install <package>. If you try you get the following output:

matt@mypc:~$ pip install matplotlib
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
    python3-xyz, where xyz is the package you are trying to
    install.

    If you wish to install a non-Debian-packaged Python package,
    create a virtual environment using python3 -m venv path/to/venv.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
    sure you have python3-full installed.

    If you wish to install a non-Debian packaged Python application,
    it may be easiest to use pipx install xyz, which will manage a
    virtual environment for you. Make sure you have pipx installed.

    See /usr/share/doc/python3.11/README.venv for more information.

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

There are two options to proceed:

Debian Managed Packages

Try and find needed modules in the packages provided by Debian distribution:

apt-get install <package>    # Install package
aptitude                     # Interface for searching and installing available packages

Virtual Environment (venv)

Install additional virtual environment as described in the message above, i.e.:

python3 -m venv ~/venv/finpy

Now either issue commands against that environments as follows:

~/venv/finpy/bin/python script1.py
~/venv/finpy/bin/pip install <package>

For further reading about pip see PIP Cheat Sheet

A more comfortable option is to switch to the environment sepcified by its path:

source ~/venv/finpy/bin/activate

Example:

matt@mypc:~$ source ~/venv/finpy/bin/activate
(finpy) matt@mypc:~$

All subsequent commands will be executed in the context of the active environment, which is now listed in parentheses.

In order to leave the virtual environment again:

matt@mypc:~$ deactivate

Windows Environments

Windows Native

Miniconda

Further reading: Miniconda Cheat Sheet

For handling PIP within Miniconda see PIP Cheat Sheet

Known Issues

Not all packages seem to work properly. Known issues:

  • yfinance.download seems not to work properly on Windows