pippython2 et pip2 (apt)def main():
print("Hello World!")
if __name__ == "__main__":
main()
<code si vrai> if <condition> else <code si faux>
| Type | Naming convention |
|---|---|
| file | snake_case.py |
| class | PascalCase |
| function | snake_case |
| variable | snake_case |
| constant | UPPER_SNAKE_CASE |
| package | lowercase |
| module | snake_case |
| Source : Python PEP8 style guide Cheat Sheet by jmds - Cheatography.com and [PEP 8 – Style Guide for Python Code | peps.python.org](https://www.python.org/dev/peps/pep-0008/#naming-conventions) |
pipWindows
python -m pip install --upgrade pip
Linux
pip install --upgrade pip
Source : python - Automatically create requirements.txt - Stack Overflow
pip install pipreqs
pipreqs /chemin/vers/le/projet --force
OU
pip freeze > requirements.txt
pip install -r requirements.txt
Source : venv — Creation of virtual environments — Python 3 documentation
# Créer un environnement virtuel
python3 -m venv venv
# Activer l'environnement virtuel
source venv/bin/activate
virtualenv
pip install virtualenvsudo apt install python3-virtualenvvenvvenv, mais optionnel avec virtualenvBut : utiliser une version différente de python que celui installé sur la machine
pip install virtualenv
ou
sudo apt install python3-virtualenv
python3 -m virtualenv -p /usr/bin/python2.7 venv-name
source venv-name/bin/activate
Vous devriez voir à présent (venv-name) dans votre terminal, vous pouvez utiliser python comme d’habitude (python monfichier.py)
python2 et pip2 (apt)apt install python2 wget
wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
python2 get-pip.py
web.archive.org/web/20111010053227/jaynes.colorado.edu/PythonGuidelines.html#module_formatting
Documentation (CLI à lire à partir de la fin de la page)
Default : lance sur localhost:8000 le dossier courant
python -m http.server
Options supplémentaires :
python -m http.server <port> --bind <ip addr> --directory <directory>
pip show pip
voir Location:
Linux :
Location: /home/myusername/.local/lib/python3.10/site-packages
Entrez dans le path : /home/myusername/.local/bin
echo 'export PATH=$PATH:/home/myusername/.local/bin' >> ~/.bashrc
source ~/.bashrc
Windows :
C:\Users\myusername\AppData\Roaming\Python\Python311\site-packages
Ajoutez la ligne suivante dans le PATH
C:\Users\myusername\AppData\Roaming\Python\Python311\Scripts