Python: Unterschied zwischen den Versionen

Aus Wikizone
Wechseln zu: Navigation, Suche
 
(Eine dazwischenliegende Version desselben Benutzers wird nicht angezeigt)
Zeile 19: Zeile 19:
  
 
=== Python & Homebrew ===
 
=== Python & Homebrew ===
 +
Siehe auch [[Homebrew]] für aktuelle Infos
 +
 
==== Hinweis ====
 
==== Hinweis ====
 
Generell scheinen die Dinge besser zu funktionieren wenn man sie alle über Homebrew installiert. Also:  
 
Generell scheinen die Dinge besser zu funktionieren wenn man sie alle über Homebrew installiert. Also:  
 
  brew install python
 
  brew install python
 
  brew install pyqt
 
  brew install pyqt
 +
 +
 
==== python ====
 
==== python ====
 
 
  brew install python
 
  brew install python
 
Installiert eine neuere Version. Es gibt ein paar Infos zur Installation aus:
 
Installiert eine neuere Version. Es gibt ein paar Infos zur Installation aus:
Zeile 93: Zeile 96:
 
See: https://docs.brew.sh/Homebrew-and-Python
 
See: https://docs.brew.sh/Homebrew-and-Python
 
</pre>
 
</pre>
 +
 +
==== Libraries ====
 +
Manchmal werden Libraries die man normalerweise mit
 +
brew install libname
 +
Installiert nicht gefunden oder erscheinen nicht. Probleme entstehen z.b. mit virtuellen Umgebungen etc.
  
 
== PIP ==
 
== PIP ==

Aktuelle Version vom 25. Februar 2025, 18:37 Uhr

Links[Bearbeiten]

https://wiki.python.org/moin/BeginnersGuide/Programmers
Python - Basics

Python auf dem Mac[Bearbeiten]

Ist standardmäßig installiert.

Aufruf von Programmen mit

python programmname

Im entsprechenden Verzeichnis im Terminal

Python Konsole bekommt man vom Terminal mit aufruf des Programms.

idle.app

Zusätzlich gibt es noch Python Launcher für verschiedene Python Versionen -> noch nicht getestet.

Python & Homebrew[Bearbeiten]

Siehe auch Homebrew für aktuelle Infos

Hinweis[Bearbeiten]

Generell scheinen die Dinge besser zu funktionieren wenn man sie alle über Homebrew installiert. Also:

brew install python
brew install pyqt


python[Bearbeiten]

brew install python

Installiert eine neuere Version. Es gibt ein paar Infos zur Installation aus:

Zu SSL

A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl@1.1/certs

and run
  /usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH, run:
  echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
  export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
  export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

Zu sqlite

sqlite is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have sqlite first in your PATH, run:
  echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.zshrc

For compilers to find sqlite you may need to set:
  export LDFLAGS="-L/usr/local/opt/sqlite/lib"
  export CPPFLAGS="-I/usr/local/opt/sqlite/include"


Zu tcs-ck

tcl-tk is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.

If you need to have tcl-tk first in your PATH, run:
  echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.zshrc

For compilers to find tcl-tk you may need to set:
  export LDFLAGS="-L/usr/local/opt/tcl-tk/lib"
  export CPPFLAGS="-I/usr/local/opt/tcl-tk/include"

Zu Python

Python has been installed as
  /usr/local/bin/python3

Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
  /usr/local/opt/python@3.9/libexec/bin

You can install Python packages with
  pip3 install <package>
They will install into the site-package directory
  /usr/local/lib/python3.9/site-packages

See: https://docs.brew.sh/Homebrew-and-Python

Libraries[Bearbeiten]

Manchmal werden Libraries die man normalerweise mit

brew install libname

Installiert nicht gefunden oder erscheinen nicht. Probleme entstehen z.b. mit virtuellen Umgebungen etc.

PIP[Bearbeiten]

Mit Homebrew[Bearbeiten]

Wenn man aktuelle Pythons mit Homebrew installiert wird pip mitinstalliert. Bei Catalina sind sie dann mit

python3

und

pip3

ansprechbar

Probleme bei normaler installation[Bearbeiten]

Beliebter Paketmanager für Python. Sollte eigentlich mit

sudo easy_install pip

Installierbar sein. Gibt bei mir Versions Probleme.

Deinstallieren:


There is no completely automatic uninstall but you can do it in two steps:

easy_install -m pip

This should remove pip from easy-install.pth and print the full path to where pip is installed. Now just manually remove the path that the previous command printed. Or you could just manually edit easy-install.pth and remove the pip sources if you know where they are located. Run command prompt as administrator Give the command

easy_install -m pip

This may not uninstall pip completely. So again give this command

pip uninstall pip 

If by previous command pip got uninstalled then this command wont run, else it will completely remove pip Now check by giving command

pip --version 

This should give pip is not recognized as an internal or external command

pyenv[Bearbeiten]

Ein weiterer Paketmanager für Python:

https://medium.com/@iamclement/how-to-install-jupyter-notebook-on-mac-using-homebrew-528c39fd530f

Step 1 — Install pyenv[Bearbeiten]

Mac Os X come with Pythong 2.7 pre-installed but many Machine Learning packages are progressing to Python 3.x. Therefore, it’s recommended you start using Python 3 and the best way to do that is to first install pyenv version manager. This will allow you to install any version of Python you'd like.

First update Homebrew package manager.

brew update && brew doctor

Install pyenv version manager.

brew install pyenv

Step 2 — Install Python[Bearbeiten]

Install Python 3.x using pyenv. You can see a list of version from Python Website.

pyenv install -l | grep -ow [0-9].[0-9].[0-9]
pyenv install 3.x.x

Double check your work.

pyenv versions

You’ll also need to configure your ~/.bash_profile.

echo 'eval "$(pyenv init -)"' >> ~/.bash_profile

Step 3 — Set Python to Local or Global[Bearbeiten]

If you only want to use Python 3.x for a specific project, then cd to your specific directory and type:

pyenv local 3.x.x

If you’d prefer to just have Python 3.x installed globally throughout your operating system, then type:

pyenv global 3.x.x

Step 4 — Install Jupyter[Bearbeiten]

Jupyter is an acronym for Julia, Python and R but these days, other languages are also included such as Ruby.

brew install jupyter

Step 5 — Start Jupyter[Bearbeiten]

Now it’s time to start the jupyter notebook.

jupyter notebook

Python IDE[Bearbeiten]

Über Anaconda können viele direkt installiert werden.

Spyder[Bearbeiten]

Kleine IDE

Anaconda[Bearbeiten]

Wahrscheinlich der einfachste Einstieg in die Python Welt. Man kann schnell auf alle Möglichen Tools zugreifen, es lassen sich verschiedenen Versionen gleichzeitig nutzen / zusammenstellen. Hat Spyder dabei - eine recht geschickte IDE zur Python-Entwicklung.

Hat auch viele wichtige Libs bereits an Bord.

Visual Studio Code[Bearbeiten]

https://code.visualstudio.com/docs/python/python-tutorial

Wichtig - du mußt VSC sagen welchen Interpreter er nutzen soll. Am besten

  • über brew python installieren.
  • Command Pallette ⇧⌘P, anfangen zu tippen um Python: Select Interpreter command zu finden, dann auswählen.
    • Oder Python Environment option in der Statusbar wenn vorhanden. Evtl. wird auch schon einer angezeigt.
    • VSC findet i.d.R. automatisch installierte Environments. Wenn nicht in Configuring Python environments suchen (siehe Link oben)
  • When using an Anaconda distribution, the correct interpreter should have the suffix ('base':conda), for example Python 3.7.3 64-bit ('base':conda).
  • Selecting an interpreter sets which interpreter will be used by the Python extension for that workspace.
  • Note: If you select an interpreter without a workspace folder open, VS Code sets python.defaultInterpreterPath in User scope instead, which sets the default interpreter for VS Code in general. The user setting makes sure you always have a default interpreter for Python projects. The workspace settings lets you override the user setting.

PyCharm[Bearbeiten]