Pip
Python install
Follow this guide.
Attention: Always use python3 (or python3.9) command. python command will point to OSX system python 2.7!
VSCode workflow
So far graphics do not show when running virtual env versions
IPython interactive console
- Add
#%%to add cells which can be run individually. - Press
Shift + Enterto run line or selection in iPython console.
Jupyter output pane
- Select code and press
Option + Enterto run selection in Jupyter Output pane
Commands
Strg + Enter: Execute cell
Tooling/packages
ipython
Run ipython to open the interactive shell.
!lsrunslsin the standard shell?nameorname?shows infos about that piece of code.
venv
NOTE: Use venv (NOT virtualenv) on OSX - the later has issues on OSX!
- In the project directory type
python3 -m venv ./env(orpython3 -m venv venv) - Activate the virtual environment using
source env/bin/activate(orsource venv/bin/activate) - Install dependencies as usual with
pip install(orpip install -r requirements.txt). Usepip listto see the dependencies installed in the current folder. - Type
deactivateto deactivate the current virtual environment.
virtualenv
Convention: Call virtualenv folder env.
- Setup:
virtualenv env - Activate virtualenv:
source env/bin/activate - Install packages (e.g.
requestspackage) with pip of virtualenv:env/bin/pip install requests(runningpip installshould automatically callenv/bin/pip install) - Find the installed packages of the environment at
env/lib/python3.7/. - To exit virtual env:
deactivate
pip
Install from existing requirements.txt
Install all files listed in a requirements.txt file:
pip install -r requirements.txtExample of requirements.txt:
requests
APScheduler
flask
flask-cors
flask-restplus
numpy
pandas
python-dotenv
Shapely
ipython
scikit-learn
SQLAlchemy
psycopg2
pyproj
boto3
requests-aws4auth
tables
tensorflow
kerasCreate own requirements.txt
Run
pip freeze > requirements.txtto create a requirements.txt file from the currently installed packages.
upgrade pip packages
Use the tool https://github.com/achillesrasquinha/pipupgrade
pipupgrade --interactivepip3 (like npm install --save-dev)
pip3 install package && pip3 freeze > requirements.txtHOW TO install new python packages on my OSX system
I’ve got homebrew and pip. The latter is a program to manage python packages
The commands are basically:
pip install <package_name>List of all packages available with pip
Work on prod. environment
Python Developers Survey 2018 Results
Options:
- miniconda + pip
- pip freeze
- pip + virtualenv
- docker + pip (with auto-generated requirements file from pycharm)
Pycharm
Use evaluate window to quickly run things (like matlab)
Poetry
- poetry is an alternative package manager for python
Create project
-
poetry newpoetry new my-project -
poetry init- Create folder and navigate to it
- Run
poetry init<— Running theinitcommand will take you into an interactive session to define the parameters of your new project. Just hit enter on each question - this will use the defaults (in the[]).
See this tutorial to start poetry with
django.
Add dependencies
poetry add name-of-dependencyEnvironment
- Run
poetry shellto start a virtual environment. Typeexitto exit.
Discuss on Twitter ● Improve this article: Edit on GitHub