SlideShare uma empresa Scribd logo
1 de 97
Baixar para ler offline
Sebastian Witowski
Python Versions and
Dependencies Made Easy
Sebastian Witowski
Python consultant, freelancer, and trainer
@SebaWitowski switowski.com
Problem with (Python) projects
@SebaWitowski switowski.com
Problem with (Python) projects
Stuck in the 90s
Over-engineered
@SebaWitowski switowski.com
Problem with (Python) projects
Over-engineered
• Too many shiny new tools from
HackerNews

• Those tools gets abandoned

• You spend too much time
replacing old tools with new ones
Stuck in the 90s
@SebaWitowski switowski.com
Problem with (Python) projects
Over-engineered
• Too many shiny new tools from
HackerNews

• Those tools gets abandoned

• You spend too much time
replacing old tools with new ones
Stuck in the 90s
• Everything managed with Bash
scripts

• You have to maintain Bash
scripts or some other scripts
(as a Python developer)
@SebaWitowski switowski.com
How about a middle ground?
@SebaWitowski switowski.com
What will we talk about?
• pyenv - installing different Python versions on your computer
@SebaWitowski switowski.com
What will we talk about?
• pyenv - installing different Python versions on your computer

• venv - isolating dependencies of your projects
@SebaWitowski switowski.com
What will we talk about?
• pyenv - installing different Python versions on your computer

• venv - isolating dependencies of your projects 

• pipx - installing global packages
@SebaWitowski switowski.com
What will we talk about?
• pyenv - installing different Python versions on your computer

• venv - isolating dependencies of your projects 

• pipx - installing global packages

• pip-tools - dependency pinning
@SebaWitowski switowski.com
Installing Python
System Python
macOS
Ubuntu 20.04
Debian 10
@SebaWitowski
• Python version preinstalled on your OS is called “system Python”
System Python
@SebaWitowski switowski.com
• Python version preinstalled on your OS is called “system Python”

• Please, don’t use it
System Python
@SebaWitowski switowski.com
• Python version preinstalled on your OS is called “system Python”

• Please, don’t use it

• And don’t update it (you might break your OS)!
System Python
@SebaWitowski switowski.com
How to install a new Python version?
@SebaWitowski switowski.com
• Use an installer from python.org
How to install a new Python version?
@SebaWitowski switowski.com
• Use an installer from python.org

• Use your package manager
How to install a new Python version?
@SebaWitowski switowski.com
• Use an installer from python.org

• Use your package manager

• Compile it from the source files
How to install a new Python version?
@SebaWitowski switowski.com
Or you can use pyenv!
https://github.com/pyenv/pyenv
@SebaWitowski switowski.com
Or pyenv-win for Windows
https://github.com/pyenv-win/pyenv-win
@SebaWitowski switowski.com
Installing pyenv
@SebaWitowski switowski.com
Installing pyenv
@SebaWitowski switowski.com
Using pyenv
1. Find Python version to install
$ pyenv install --list
Available versions:
2.1.3
2.2.3
2.3.7
2.4.0
2.4.1
2.4.2
2.4.3
2.4.4
2.4.5
2.4.6
2.5.0
2.5.1
2.5.2
2.5.3
2.5.4
...
...
3.9.0
3.9-dev
3.10-dev
activepython-2.7.14
activepython-3.5.4
activepython-3.6.0
anaconda-1.4.0
anaconda-1.5.0
anaconda-1.5.1
anaconda-1.6.0
anaconda-1.6.1
anaconda-1.7.0
anaconda-1.8.0
anaconda-1.9.0
...
...
miniconda3-4.7.12
pypy-c-jit-latest
pypy-c-nojit-latest
pypy-dev
pypy-stm-2.3
pypy-stm-2.5.1
pypy-1.5-src
pypy-1.5
pypy-1.6
pypy-1.7
pypy-1.8
pypy-1.9
pypy-2.0-src
pypy-2.0
...
...
pypy3.6-7.3.0
pypy3.6-7.3.1-src
pypy3.6-7.3.1
pyston-0.5.1
pyston-0.6.0
pyston-0.6.1
stackless-dev
stackless-2.7-dev
stackless-2.7.2
stackless-2.7.3
stackless-2.7.4
stackless-2.7.5
stackless-2.7.6
...
@SebaWitowski switowski.com
Using pyenv
1. Find Python version to install
2. Install it
$ pyenv install 3.9.0
...
# Wait for a few minutes
...
# Done!
@SebaWitowski switowski.com
Using pyenv
1. Find Python version to install
2. Install it
3. Check if it’s installed correctly
$ pyenv versions
* system
3.9.0
@SebaWitowski switowski.com
Using pyenv
1. Find Python version to install
2. Install it
3. Check if it’s installed correctly
4. Start using this version
$ pyenv global 3.9.0
# or
$ pyenv local 3.9.0
# or
$ pyenv shell 3.9.0
@SebaWitowski switowski.com
3 levels of pyenv
• pyenv global 3.9.0 - changes the global Python version on your computer
@SebaWitowski switowski.com
3 levels of pyenv
• pyenv global 3.9.0 - changes the global Python version on your computer

• pyenv local 3.9.0 - changes Python version for the current folder and all the
sub-folders
@SebaWitowski switowski.com
3 levels of pyenv
• pyenv global 3.9.0 - changes the global Python version on your computer

• pyenv local 3.9.0 - changes Python version for the current folder and all the
sub-folders
# projectA
$ pyenv local 3.9.0
# projectB
$ pyenv local 3.6.0
@SebaWitowski switowski.com
3 levels of pyenv
• pyenv global 3.9.0 - changes the global Python version on your computer

• pyenv local 3.9.0 - changes Python version for the current folder and all the
sub-folders

• pyenv shell 2.7.18 - changes Python version for the current shell session
@SebaWitowski switowski.com
Problem with pip
You can only have one version of a given package installed!
@SebaWitowski switowski.com
$ pip install Django
...
Django 3.0 installed!
Problem with pip
@SebaWitowski switowski.com
Problem with pip
$ pip install Django==2.2
...
...
...
Django 2.2 installed!
@SebaWitowski switowski.com
$ pip install Django==2.2
...
Django==3.0 uninstalled!
...
Django 2.2 installed!
Problem with pip
@SebaWitowski switowski.com
# .../lib/python3.9/site-packages
$ ls -al
...
drwxr-xr-x 22 switowski 704 Oct 30 12:41 django/
drwxr-xr-x 12 switowski 384 Oct 30 12:41 django_redis/
drwxr-xr-x 16 switowski 512 Sep 28 17:58 docutils/
...
Problem with pip
@SebaWitowski switowski.com
# .../lib/python3.9/site-packages
$ ls -al
...
drwxr-xr-x 22 switowski 704 Oct 30 12:41 django/
drwxr-xr-x 12 switowski 384 Oct 30 12:41 django_redis/
drwxr-xr-x 16 switowski 512 Sep 28 17:58 docutils/
...
Problem with pip
@SebaWitowski switowski.com
Virtual environment
If pip installs every package in the same folder, why can’t we tell
it to temporarily install them in a different folder?
@SebaWitowski switowski.com
Virtual environment
If pip installs every package in the same folder, why can’t we tell
it to temporarily install them in a different folder?
Virtual environment:

• Creates a special folder with Python binaries

• Tells pip to install new packages to that folder

• Tells Python to use packages from that folder
@SebaWitowski switowski.com
Using virtual environments
1. Create new virtual environment
$ python -m venv .venv
@SebaWitowski switowski.com
Using virtual environments
1. Create new virtual environment
2. Activate it
$ source .venv/bin/activate
@SebaWitowski switowski.com
Using virtual environments
1. Create new virtual environment
2. Activate it
$ source .venv/bin/activate
# Your prompt should change:
(venv) $
@SebaWitowski switowski.com
Using virtual environments
1. Create new virtual environment
2. Activate it
3. Work on your Python project (install packages, run Python)
(venv) $ pip install Django==2.2
...
(venv) $ python manage.py runserver
@SebaWitowski switowski.com
Using virtual environments
1. Create new virtual environment
2. Activate it
3. Work on your Python project (install packages, run Python)
4. Deactivate virtual environment to stop using it
(venv) $ deactivate
$
@SebaWitowski switowski.com
Typical workflow
# Inside Django 3 project folder
$ python -m venv django3-app
$ source django3-app/bin/activate
$ pip install django==3.0
# Inside Django 2 project folder
$ python -m venv django2-app
$ source django2-app/bin/activate
$ pip install django==2.2
@SebaWitowski switowski.com
virtualenvwrapper
Windows users: https://pypi.org/project/virtualenvwrapper-win/
Linux and macOS:
@SebaWitowski switowski.com
virtualenvwrapper
virtualenvwrapper stores all virtual environments in:
~/.virtualenvs/
@SebaWitowski switowski.com
virtualenvwrapper
virtualenvwrapper stores all virtual environments in:
~/.virtualenvs/
$ mkvirtualenv django2-app - create a virtual environment
$ workon django2-app - activate it
$ lsvirtualenv - list all virtual environments
$ rmvirtualenv django2-app - delete a virtual environment
@SebaWitowski switowski.com
venv or virtualenvwrapper?
@SebaWitowski switowski.com
Global Python packages
• Some tools should be installed globally (black, flake8, virtualenvwrapper)
@SebaWitowski switowski.com
Global Python packages
• Some tools should be installed globally (black, flake8, virtualenvwrapper)

• But if they require different versions of the same dependency, one of them
will break
@SebaWitowski switowski.com
Global Python packages
• Some tools should be installed globally (black, flake8, virtualenvwrapper)

• But if they require different versions of the same dependency, one of them
will break

• Installing global tools into separate virtual environments is a hassle (you
have to activate each virtual environment to use that tool)
@SebaWitowski switowski.com
pipx - global packages in separate environments
https://github.com/pipxproject/pipx
@SebaWitowski switowski.com
pipx in action
1. Install “black” package
$ pipx install black
installed package black 20.8b1, Python 3.8.5
These apps are now globally available
- black
- black-primer
- blackd
done! ✨ 🌟 ✨
@SebaWitowski switowski.com
pipx in action
1. Install “black” package
2. Use black
$ black hello_world.py
reformatted hello_world.py
All done! ✨ 🍰 ✨
1 file reformatted.
@SebaWitowski switowski.com
pipx in action
1. Install “black” package
2. Use black
3. “black” installed in a virtual env will shadow the global one
# Inside a virtual environment
(venv) $ black --version
black, version 19.3b0
# Outside of a virtual environment
$ black --version
black, version 20.8b1
@SebaWitowski switowski.com
pipx commands
$ pipx list - list all installed packages
$ pipx uninstall <package> - uninstall package
$ pipx upgrade-all - upgrade all packages
$ pipx inject pytest pytest-cov - install pytest-cov inside
pytest virtual env
@SebaWitowski switowski.com
Dependencies in your project
@SebaWitowski switowski.com
Dependencies in your project
# requirements.txt
Django
django-redis
pytest
@SebaWitowski switowski.com
Dependencies in your project
# requirements.txt
Django
django-redis
pytest
$ pip install -r requirements.txt
...
Successfully installed Django-2.2, ...
@SebaWitowski switowski.com
Dependencies in your project
# requirements.txt
Django
django-redis
pytest
$ pip install -r requirements.txt
...
Successfully installed Django-2.2, ...
$ pip install -r requirements.txt
...
Successfully installed Django-3.0, ...
One month later…
Dependencies in your project
# requirements.txt
Django
django-redis
pytest
$ pip install -r requirements.txt
...
Successfully installed Django-2.2, ...
$ pip install -r requirements.txt
...
Successfully installed Django-3.0, ...
One month later…
Dependencies in your project
# requirements.txt
Django>=2.2,<3.0
django-redis==4.12.0
pytest==5.*
Dependency pinning:
@SebaWitowski switowski.com
Dependencies in your project
Always pin dependencies on production servers!
@SebaWitowski switowski.com
Dependencies in your project
Always pin dependencies on production servers!
And their sub-dependencies (3rd party packages)!
@SebaWitowski switowski.com
Dependencies in your project
Always pin dependencies on production servers!
And their sub-dependencies (3rd party packages)!
And don’t forget to update packages regularly!
@SebaWitowski switowski.com
Dependencies in your project
Always pin dependencies on production servers!
And their sub-dependencies (3rd party packages)!
And don’t forget to update packages regularly!
That’s a lot of work!
@SebaWitowski switowski.com
Pipenv and Poetry to the rescue!
But do you really need them?
@SebaWitowski switowski.com
But do you really need them?
• What if they stop working?
@SebaWitowski switowski.com
But do you really need them?
• What if they stop working?

• What if they get discontinued?
@SebaWitowski switowski.com
But do you really need them?
• What if they stop working?

• What if they get discontinued?

• Do you really use ALL their features?
@SebaWitowski switowski.com
Pipenv and Poetry are great
@SebaWitowski switowski.com
But sometimes a simpler tool is enough
Pipenv and Poetry are great
@SebaWitowski switowski.com
But sometimes a simpler tool is enough
Pipenv and Poetry are great
https://github.com/jazzband/pip-tools
@SebaWitowski switowski.com
pip-compile
@SebaWitowski switowski.com
pip-compile
# requirements.in
Django>=2.2>,<3.0
pytest
# requirements.txt
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile requirements.in
#
attrs==20.2.0 # via pytest
django==2.2.17 # via -r requirements.in
importlib-metadata==2.0.0 # via pluggy, pytest
iniconfig==1.1.1 # via pytest
packaging==20.4 # via pytest
pluggy==0.13.1 # via pytest
py==1.9.0 # via pytest
pyparsing==2.4.7 # via packaging
pytest==6.1.2 # via -r requirements.in
pytz==2020.4 # via django
six==1.15.0 # via packaging
sqlparse==0.4.1 # via django
toml==0.10.2 # via pytest
zipp==3.4.0 # via importlib-metadata
$ pip-compile requirements.in
pip-compile
# requirements.txt
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile requirements.in
#
attrs==20.2.0 # via pytest
django==2.2.17 # via -r requirements.in
importlib-metadata==2.0.0 # via pluggy, pytest
iniconfig==1.1.1 # via pytest
packaging==20.4 # via pytest
pluggy==0.13.1 # via pytest
py==1.9.0 # via pytest
pyparsing==2.4.7 # via packaging
pytest==6.1.2 # via -r requirements.in
pytz==2020.4 # via django
six==1.15.0 # via packaging
sqlparse==0.4.1 # via django
toml==0.10.2 # via pytest
zipp==3.4.0 # via importlib-metadata
@SebaWitowski switowski.com
pip-compile
# requirements.txt
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile requirements.in
#
attrs==20.2.0 # via pytest
django==2.2.17 # via -r requirements.in
importlib-metadata==2.0.0 # via pluggy, pytest
iniconfig==1.1.1 # via pytest
packaging==20.4 # via pytest
pluggy==0.13.1 # via pytest
py==1.9.0 # via pytest
pyparsing==2.4.7 # via packaging
pytest==6.1.2 # via -r requirements.in
pytz==2020.4 # via django
six==1.15.0 # via packaging
sqlparse==0.4.1 # via django
toml==0.10.2 # via pytest
zipp==3.4.0 # via importlib-metadata
@SebaWitowski switowski.com
pip-compile
# requirements.txt
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile requirements.in
#
attrs==20.2.0 # via pytest
django==2.2.17 # via -r requirements.in
importlib-metadata==2.0.0 # via pluggy, pytest
iniconfig==1.1.1 # via pytest
packaging==20.4 # via pytest
pluggy==0.13.1 # via pytest
py==1.9.0 # via pytest
pyparsing==2.4.7 # via packaging
pytest==6.1.2 # via -r requirements.in
pytz==2020.4 # via django
six==1.15.0 # via packaging
sqlparse==0.4.1 # via django
toml==0.10.2 # via pytest
zipp==3.4.0 # via importlib-metadata
@SebaWitowski switowski.com
pip-compile
# requirements.txt
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile requirements.in
#
attrs==20.2.0 # via pytest
django==2.2.17 # via -r requirements.in
importlib-metadata==2.0.0 # via pluggy, pytest
iniconfig==1.1.1 # via pytest
packaging==20.4 # via pytest
pluggy==0.13.1 # via pytest
py==1.9.0 # via pytest
pyparsing==2.4.7 # via packaging
pytest==6.1.2 # via -r requirements.in
pytz==2020.4 # via django
six==1.15.0 # via packaging
sqlparse==0.4.1 # via django
toml==0.10.2 # via pytest
zipp==3.4.0 # via importlib-metadata
@SebaWitowski switowski.com
pip-compile
# requirements.txt
#
# This file is autogenerated by pip-compile
# To update, run:
#
# pip-compile requirements.in
#
attrs==20.2.0 # via pytest
django==2.2.17 # via -r requirements.in
importlib-metadata==2.0.0 # via pluggy, pytest
iniconfig==1.1.1 # via pytest
packaging==20.4 # via pytest
pluggy==0.13.1 # via pytest
py==1.9.0 # via pytest
pyparsing==2.4.7 # via packaging
pytest==6.1.2 # via -r requirements.in
pytz==2020.4 # via django
six==1.15.0 # via packaging
sqlparse==0.4.1 # via django
toml==0.10.2 # via pytest
zipp==3.4.0 # via importlib-metadata
@SebaWitowski switowski.com
pip-compile
Now, run:
$ pip install -r requirements.txt
@SebaWitowski switowski.com
pip-compile
Now, run:
$ pip install -r requirements.txt
Need to update dependencies?
$ pip-compile requirements.in
@SebaWitowski switowski.com
pip-compile
Make pip-compile part of your CI
@SebaWitowski switowski.com
pip-compile
Make pip-compile part of your CI
If something breaks, pin that package in requirements.in
@SebaWitowski switowski.com
pip-sync
@SebaWitowski switowski.com
pip-tools
vs.
Pipenv and Poetry
@SebaWitowski switowski.com
Summary
@SebaWitowski switowski.com
Summary
• Use pyenv to install/update Python versions
@SebaWitowski switowski.com
Summary
• Use pyenv to install/update Python versions
• Use venv/virtualenvwrapper to isolate dependencies of your projects
@SebaWitowski switowski.com
Summary
• Use pyenv to install/update Python versions
• Use venv/virtualenvwrapper to isolate dependencies of your projects
• Use pipx to install global tools
@SebaWitowski switowski.com
Summary
• Use pyenv to install/update Python versions
• Use venv/virtualenvwrapper to isolate dependencies of your projects
• Use pipx to install global tools
• Consider pip-tools when you just need to pin dependencies
@SebaWitowski switowski.com
Where to go next?
@SebaWitowski switowski.com
Where to go next?
“Modern Python Projects” workshop (part of this conference)
@SebaWitowski switowski.com
Where to go next?
“Modern Python Projects” online course
https://modernpythonprojects.com/
@SebaWitowski switowski.com

Mais conteúdo relacionado

Mais procurados

2017 jenkins world
2017 jenkins world2017 jenkins world
2017 jenkins worldBrent Laster
 
How Prometheus Store the Data
How Prometheus Store the DataHow Prometheus Store the Data
How Prometheus Store the DataHao Chen
 
Managing your Hadoop Clusters with Apache Ambari
Managing your Hadoop Clusters with Apache AmbariManaging your Hadoop Clusters with Apache Ambari
Managing your Hadoop Clusters with Apache AmbariDataWorks Summit
 
Spark SQL Beyond Official Documentation
Spark SQL Beyond Official DocumentationSpark SQL Beyond Official Documentation
Spark SQL Beyond Official DocumentationDatabricks
 
The Alfresco ECM 1 Billion Document Benchmark on AWS and Aurora - Benchmark ...
The Alfresco ECM 1 Billion Document Benchmark on AWS and Aurora  - Benchmark ...The Alfresco ECM 1 Billion Document Benchmark on AWS and Aurora  - Benchmark ...
The Alfresco ECM 1 Billion Document Benchmark on AWS and Aurora - Benchmark ...Symphony Software Foundation
 
Practical Windows Kernel Exploitation
Practical Windows Kernel ExploitationPractical Windows Kernel Exploitation
Practical Windows Kernel ExploitationzeroSteiner
 
Zeppelin(Spark)으로 데이터 분석하기
Zeppelin(Spark)으로 데이터 분석하기Zeppelin(Spark)으로 데이터 분석하기
Zeppelin(Spark)으로 데이터 분석하기SangWoo Kim
 
Finite State Queries In Lucene
Finite State Queries In LuceneFinite State Queries In Lucene
Finite State Queries In Luceneotisg
 
Python to go
Python to goPython to go
Python to goWeng Wei
 
ksqlDB로 실시간 데이터 변환 및 스트림 처리
ksqlDB로 실시간 데이터 변환 및 스트림 처리ksqlDB로 실시간 데이터 변환 및 스트림 처리
ksqlDB로 실시간 데이터 변환 및 스트림 처리confluent
 
Operating and Supporting Delta Lake in Production
Operating and Supporting Delta Lake in ProductionOperating and Supporting Delta Lake in Production
Operating and Supporting Delta Lake in ProductionDatabricks
 
BI, Reporting and Analytics on Apache Cassandra
BI, Reporting and Analytics on Apache CassandraBI, Reporting and Analytics on Apache Cassandra
BI, Reporting and Analytics on Apache CassandraVictor Coustenoble
 
Integrating Jira Software Cloud With the AWS Code Suite
Integrating Jira Software Cloud With the AWS Code SuiteIntegrating Jira Software Cloud With the AWS Code Suite
Integrating Jira Software Cloud With the AWS Code SuiteAtlassian
 
SASS - Syntactically Awesome Stylesheet
SASS - Syntactically Awesome StylesheetSASS - Syntactically Awesome Stylesheet
SASS - Syntactically Awesome StylesheetNeha Sharma
 
Sizing your alfresco platform
Sizing your alfresco platformSizing your alfresco platform
Sizing your alfresco platformLuis Cabaceira
 
Building Scalable Data Pipelines - 2016 DataPalooza Seattle
Building Scalable Data Pipelines - 2016 DataPalooza SeattleBuilding Scalable Data Pipelines - 2016 DataPalooza Seattle
Building Scalable Data Pipelines - 2016 DataPalooza SeattleEvan Chan
 
Cassandra vs. ScyllaDB: Evolutionary Differences
Cassandra vs. ScyllaDB: Evolutionary DifferencesCassandra vs. ScyllaDB: Evolutionary Differences
Cassandra vs. ScyllaDB: Evolutionary DifferencesScyllaDB
 

Mais procurados (20)

2017 jenkins world
2017 jenkins world2017 jenkins world
2017 jenkins world
 
How Prometheus Store the Data
How Prometheus Store the DataHow Prometheus Store the Data
How Prometheus Store the Data
 
Managing your Hadoop Clusters with Apache Ambari
Managing your Hadoop Clusters with Apache AmbariManaging your Hadoop Clusters with Apache Ambari
Managing your Hadoop Clusters with Apache Ambari
 
File Format Benchmark - Avro, JSON, ORC and Parquet
File Format Benchmark - Avro, JSON, ORC and ParquetFile Format Benchmark - Avro, JSON, ORC and Parquet
File Format Benchmark - Avro, JSON, ORC and Parquet
 
Spark SQL Beyond Official Documentation
Spark SQL Beyond Official DocumentationSpark SQL Beyond Official Documentation
Spark SQL Beyond Official Documentation
 
The Alfresco ECM 1 Billion Document Benchmark on AWS and Aurora - Benchmark ...
The Alfresco ECM 1 Billion Document Benchmark on AWS and Aurora  - Benchmark ...The Alfresco ECM 1 Billion Document Benchmark on AWS and Aurora  - Benchmark ...
The Alfresco ECM 1 Billion Document Benchmark on AWS and Aurora - Benchmark ...
 
Practical Windows Kernel Exploitation
Practical Windows Kernel ExploitationPractical Windows Kernel Exploitation
Practical Windows Kernel Exploitation
 
Zeppelin(Spark)으로 데이터 분석하기
Zeppelin(Spark)으로 데이터 분석하기Zeppelin(Spark)으로 데이터 분석하기
Zeppelin(Spark)으로 데이터 분석하기
 
Finite State Queries In Lucene
Finite State Queries In LuceneFinite State Queries In Lucene
Finite State Queries In Lucene
 
Python to go
Python to goPython to go
Python to go
 
ksqlDB로 실시간 데이터 변환 및 스트림 처리
ksqlDB로 실시간 데이터 변환 및 스트림 처리ksqlDB로 실시간 데이터 변환 및 스트림 처리
ksqlDB로 실시간 데이터 변환 및 스트림 처리
 
HBase Low Latency
HBase Low LatencyHBase Low Latency
HBase Low Latency
 
Operating and Supporting Delta Lake in Production
Operating and Supporting Delta Lake in ProductionOperating and Supporting Delta Lake in Production
Operating and Supporting Delta Lake in Production
 
BI, Reporting and Analytics on Apache Cassandra
BI, Reporting and Analytics on Apache CassandraBI, Reporting and Analytics on Apache Cassandra
BI, Reporting and Analytics on Apache Cassandra
 
Integrating Jira Software Cloud With the AWS Code Suite
Integrating Jira Software Cloud With the AWS Code SuiteIntegrating Jira Software Cloud With the AWS Code Suite
Integrating Jira Software Cloud With the AWS Code Suite
 
SASS - Syntactically Awesome Stylesheet
SASS - Syntactically Awesome StylesheetSASS - Syntactically Awesome Stylesheet
SASS - Syntactically Awesome Stylesheet
 
Api observability
Api observability Api observability
Api observability
 
Sizing your alfresco platform
Sizing your alfresco platformSizing your alfresco platform
Sizing your alfresco platform
 
Building Scalable Data Pipelines - 2016 DataPalooza Seattle
Building Scalable Data Pipelines - 2016 DataPalooza SeattleBuilding Scalable Data Pipelines - 2016 DataPalooza Seattle
Building Scalable Data Pipelines - 2016 DataPalooza Seattle
 
Cassandra vs. ScyllaDB: Evolutionary Differences
Cassandra vs. ScyllaDB: Evolutionary DifferencesCassandra vs. ScyllaDB: Evolutionary Differences
Cassandra vs. ScyllaDB: Evolutionary Differences
 

Semelhante a Python Versions and Dependencies Made Easy with pyenv, venv, pipx and pip-tools

5 minute intro to virtualenv
5 minute intro to virtualenv5 minute intro to virtualenv
5 minute intro to virtualenvamenasse
 
Python virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutesPython virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutesLarry Cai
 
Run Python on windows
Run Python on windowsRun Python on windows
Run Python on windowsSitthykun LY
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvMarkus Zapke-Gründemann
 
Pip + virtualenv
Pip + virtualenvPip + virtualenv
Pip + virtualenvDaryl Yu
 
A.I. Exercise.
A.I. Exercise.A.I. Exercise.
A.I. Exercise.Mario Cho
 
AWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
AWS EC2 Ubuntu Instance - Step-by-Step Deployment GuideAWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
AWS EC2 Ubuntu Instance - Step-by-Step Deployment GuideRapidValue
 
Symfony Live NYC 2014 - Rock Solid Deployment of Symfony Apps
Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony AppsSymfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps
Symfony Live NYC 2014 - Rock Solid Deployment of Symfony AppsPablo Godel
 
Python Dependency Management - PyconDE 2018
Python Dependency Management - PyconDE 2018Python Dependency Management - PyconDE 2018
Python Dependency Management - PyconDE 2018Patrick Muehlbauer
 
Django Dev Environment Howto
Django Dev Environment HowtoDjango Dev Environment Howto
Django Dev Environment HowtoTzu-ping Chung
 
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony AppsSymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony AppsPablo Godel
 
Packaging in Python? Don't Roll the Dice.
Packaging in Python? Don't Roll the Dice.Packaging in Python? Don't Roll the Dice.
Packaging in Python? Don't Roll the Dice.ldaws
 
Australian Bioinformatics Conference (ABiC) 2014 Talk - Doing bioinformatics ...
Australian Bioinformatics Conference (ABiC) 2014 Talk - Doing bioinformatics ...Australian Bioinformatics Conference (ABiC) 2014 Talk - Doing bioinformatics ...
Australian Bioinformatics Conference (ABiC) 2014 Talk - Doing bioinformatics ...The University of Queensland
 
20120524 english lt2_pythontoolsfortesting
20120524 english lt2_pythontoolsfortesting20120524 english lt2_pythontoolsfortesting
20120524 english lt2_pythontoolsfortestingKazuhiro Oinuma
 
The Scientific Filesystem
The Scientific FilesystemThe Scientific Filesystem
The Scientific FilesystemVanessa S
 

Semelhante a Python Versions and Dependencies Made Easy with pyenv, venv, pipx and pip-tools (20)

5 minute intro to virtualenv
5 minute intro to virtualenv5 minute intro to virtualenv
5 minute intro to virtualenv
 
Python environments
Python environmentsPython environments
Python environments
 
Python virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutesPython virtualenv & pip in 90 minutes
Python virtualenv & pip in 90 minutes
 
Run Python on windows
Run Python on windowsRun Python on windows
Run Python on windows
 
Virtualenv
VirtualenvVirtualenv
Virtualenv
 
Arbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenvArbeiten mit distribute, pip und virtualenv
Arbeiten mit distribute, pip und virtualenv
 
Python+gradle
Python+gradlePython+gradle
Python+gradle
 
Pip + virtualenv
Pip + virtualenvPip + virtualenv
Pip + virtualenv
 
A.I. Exercise.
A.I. Exercise.A.I. Exercise.
A.I. Exercise.
 
AWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
AWS EC2 Ubuntu Instance - Step-by-Step Deployment GuideAWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
AWS EC2 Ubuntu Instance - Step-by-Step Deployment Guide
 
Symfony Live NYC 2014 - Rock Solid Deployment of Symfony Apps
Symfony Live NYC 2014 -  Rock Solid Deployment of Symfony AppsSymfony Live NYC 2014 -  Rock Solid Deployment of Symfony Apps
Symfony Live NYC 2014 - Rock Solid Deployment of Symfony Apps
 
Python Dependency Management - PyconDE 2018
Python Dependency Management - PyconDE 2018Python Dependency Management - PyconDE 2018
Python Dependency Management - PyconDE 2018
 
Introduction to robot framework
Introduction to robot frameworkIntroduction to robot framework
Introduction to robot framework
 
Django Dev Environment Howto
Django Dev Environment HowtoDjango Dev Environment Howto
Django Dev Environment Howto
 
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony AppsSymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
SymfonyCon Madrid 2014 - Rock Solid Deployment of Symfony Apps
 
Packaging in Python? Don't Roll the Dice.
Packaging in Python? Don't Roll the Dice.Packaging in Python? Don't Roll the Dice.
Packaging in Python? Don't Roll the Dice.
 
Australian Bioinformatics Conference (ABiC) 2014 Talk - Doing bioinformatics ...
Australian Bioinformatics Conference (ABiC) 2014 Talk - Doing bioinformatics ...Australian Bioinformatics Conference (ABiC) 2014 Talk - Doing bioinformatics ...
Australian Bioinformatics Conference (ABiC) 2014 Talk - Doing bioinformatics ...
 
An introduction to SVN
An introduction to SVNAn introduction to SVN
An introduction to SVN
 
20120524 english lt2_pythontoolsfortesting
20120524 english lt2_pythontoolsfortesting20120524 english lt2_pythontoolsfortesting
20120524 english lt2_pythontoolsfortesting
 
The Scientific Filesystem
The Scientific FilesystemThe Scientific Filesystem
The Scientific Filesystem
 

Mais de Sebastian Witowski

5 Things I Wish I Knew About Gitlab CI
5 Things I Wish I Knew About Gitlab CI5 Things I Wish I Knew About Gitlab CI
5 Things I Wish I Knew About Gitlab CISebastian Witowski
 
Productivity tips for developers
Productivity tips for developersProductivity tips for developers
Productivity tips for developersSebastian Witowski
 
Wait, IPython can do that?! (30 minutes)
Wait, IPython can do that?! (30 minutes)Wait, IPython can do that?! (30 minutes)
Wait, IPython can do that?! (30 minutes)Sebastian Witowski
 
It's 2019 & I'm still using Python 2! Should I be worried?
It's 2019 & I'm still using Python 2! Should I be worried?It's 2019 & I'm still using Python 2! Should I be worried?
It's 2019 & I'm still using Python 2! Should I be worried?Sebastian Witowski
 

Mais de Sebastian Witowski (7)

5 Things I Wish I Knew About Gitlab CI
5 Things I Wish I Knew About Gitlab CI5 Things I Wish I Knew About Gitlab CI
5 Things I Wish I Knew About Gitlab CI
 
Optimizing Your CI Pipelines
Optimizing Your CI PipelinesOptimizing Your CI Pipelines
Optimizing Your CI Pipelines
 
Writing Faster Python 3
Writing Faster Python 3Writing Faster Python 3
Writing Faster Python 3
 
Productivity tips for developers
Productivity tips for developersProductivity tips for developers
Productivity tips for developers
 
Wait, IPython can do that?! (30 minutes)
Wait, IPython can do that?! (30 minutes)Wait, IPython can do that?! (30 minutes)
Wait, IPython can do that?! (30 minutes)
 
It's 2019 & I'm still using Python 2! Should I be worried?
It's 2019 & I'm still using Python 2! Should I be worried?It's 2019 & I'm still using Python 2! Should I be worried?
It's 2019 & I'm still using Python 2! Should I be worried?
 
Wait, IPython can do that?
Wait, IPython can do that?Wait, IPython can do that?
Wait, IPython can do that?
 

Último

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....ShaimaaMohamedGalal
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 

Último (20)

Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Clustering techniques data mining book ....
Clustering techniques data mining book ....Clustering techniques data mining book ....
Clustering techniques data mining book ....
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 

Python Versions and Dependencies Made Easy with pyenv, venv, pipx and pip-tools

  • 1. Sebastian Witowski Python Versions and Dependencies Made Easy
  • 2. Sebastian Witowski Python consultant, freelancer, and trainer @SebaWitowski switowski.com
  • 3. Problem with (Python) projects @SebaWitowski switowski.com
  • 4. Problem with (Python) projects Stuck in the 90s Over-engineered @SebaWitowski switowski.com
  • 5. Problem with (Python) projects Over-engineered • Too many shiny new tools from HackerNews • Those tools gets abandoned • You spend too much time replacing old tools with new ones Stuck in the 90s @SebaWitowski switowski.com
  • 6. Problem with (Python) projects Over-engineered • Too many shiny new tools from HackerNews • Those tools gets abandoned • You spend too much time replacing old tools with new ones Stuck in the 90s • Everything managed with Bash scripts • You have to maintain Bash scripts or some other scripts (as a Python developer) @SebaWitowski switowski.com
  • 7. How about a middle ground? @SebaWitowski switowski.com
  • 8. What will we talk about? • pyenv - installing different Python versions on your computer @SebaWitowski switowski.com
  • 9. What will we talk about? • pyenv - installing different Python versions on your computer • venv - isolating dependencies of your projects @SebaWitowski switowski.com
  • 10. What will we talk about? • pyenv - installing different Python versions on your computer • venv - isolating dependencies of your projects • pipx - installing global packages @SebaWitowski switowski.com
  • 11. What will we talk about? • pyenv - installing different Python versions on your computer • venv - isolating dependencies of your projects • pipx - installing global packages • pip-tools - dependency pinning @SebaWitowski switowski.com
  • 14. • Python version preinstalled on your OS is called “system Python” System Python @SebaWitowski switowski.com
  • 15. • Python version preinstalled on your OS is called “system Python” • Please, don’t use it System Python @SebaWitowski switowski.com
  • 16. • Python version preinstalled on your OS is called “system Python” • Please, don’t use it • And don’t update it (you might break your OS)! System Python @SebaWitowski switowski.com
  • 17. How to install a new Python version? @SebaWitowski switowski.com
  • 18. • Use an installer from python.org How to install a new Python version? @SebaWitowski switowski.com
  • 19. • Use an installer from python.org • Use your package manager How to install a new Python version? @SebaWitowski switowski.com
  • 20. • Use an installer from python.org • Use your package manager • Compile it from the source files How to install a new Python version? @SebaWitowski switowski.com
  • 21. Or you can use pyenv! https://github.com/pyenv/pyenv @SebaWitowski switowski.com
  • 22. Or pyenv-win for Windows https://github.com/pyenv-win/pyenv-win @SebaWitowski switowski.com
  • 25. Using pyenv 1. Find Python version to install $ pyenv install --list Available versions: 2.1.3 2.2.3 2.3.7 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 ... ... 3.9.0 3.9-dev 3.10-dev activepython-2.7.14 activepython-3.5.4 activepython-3.6.0 anaconda-1.4.0 anaconda-1.5.0 anaconda-1.5.1 anaconda-1.6.0 anaconda-1.6.1 anaconda-1.7.0 anaconda-1.8.0 anaconda-1.9.0 ... ... miniconda3-4.7.12 pypy-c-jit-latest pypy-c-nojit-latest pypy-dev pypy-stm-2.3 pypy-stm-2.5.1 pypy-1.5-src pypy-1.5 pypy-1.6 pypy-1.7 pypy-1.8 pypy-1.9 pypy-2.0-src pypy-2.0 ... ... pypy3.6-7.3.0 pypy3.6-7.3.1-src pypy3.6-7.3.1 pyston-0.5.1 pyston-0.6.0 pyston-0.6.1 stackless-dev stackless-2.7-dev stackless-2.7.2 stackless-2.7.3 stackless-2.7.4 stackless-2.7.5 stackless-2.7.6 ... @SebaWitowski switowski.com
  • 26. Using pyenv 1. Find Python version to install 2. Install it $ pyenv install 3.9.0 ... # Wait for a few minutes ... # Done! @SebaWitowski switowski.com
  • 27. Using pyenv 1. Find Python version to install 2. Install it 3. Check if it’s installed correctly $ pyenv versions * system 3.9.0 @SebaWitowski switowski.com
  • 28. Using pyenv 1. Find Python version to install 2. Install it 3. Check if it’s installed correctly 4. Start using this version $ pyenv global 3.9.0 # or $ pyenv local 3.9.0 # or $ pyenv shell 3.9.0 @SebaWitowski switowski.com
  • 29. 3 levels of pyenv • pyenv global 3.9.0 - changes the global Python version on your computer @SebaWitowski switowski.com
  • 30. 3 levels of pyenv • pyenv global 3.9.0 - changes the global Python version on your computer • pyenv local 3.9.0 - changes Python version for the current folder and all the sub-folders @SebaWitowski switowski.com
  • 31. 3 levels of pyenv • pyenv global 3.9.0 - changes the global Python version on your computer • pyenv local 3.9.0 - changes Python version for the current folder and all the sub-folders # projectA $ pyenv local 3.9.0 # projectB $ pyenv local 3.6.0 @SebaWitowski switowski.com
  • 32. 3 levels of pyenv • pyenv global 3.9.0 - changes the global Python version on your computer • pyenv local 3.9.0 - changes Python version for the current folder and all the sub-folders • pyenv shell 2.7.18 - changes Python version for the current shell session @SebaWitowski switowski.com
  • 33. Problem with pip You can only have one version of a given package installed! @SebaWitowski switowski.com
  • 34. $ pip install Django ... Django 3.0 installed! Problem with pip @SebaWitowski switowski.com
  • 35. Problem with pip $ pip install Django==2.2 ... ... ... Django 2.2 installed! @SebaWitowski switowski.com
  • 36. $ pip install Django==2.2 ... Django==3.0 uninstalled! ... Django 2.2 installed! Problem with pip @SebaWitowski switowski.com
  • 37. # .../lib/python3.9/site-packages $ ls -al ... drwxr-xr-x 22 switowski 704 Oct 30 12:41 django/ drwxr-xr-x 12 switowski 384 Oct 30 12:41 django_redis/ drwxr-xr-x 16 switowski 512 Sep 28 17:58 docutils/ ... Problem with pip @SebaWitowski switowski.com
  • 38. # .../lib/python3.9/site-packages $ ls -al ... drwxr-xr-x 22 switowski 704 Oct 30 12:41 django/ drwxr-xr-x 12 switowski 384 Oct 30 12:41 django_redis/ drwxr-xr-x 16 switowski 512 Sep 28 17:58 docutils/ ... Problem with pip @SebaWitowski switowski.com
  • 39. Virtual environment If pip installs every package in the same folder, why can’t we tell it to temporarily install them in a different folder? @SebaWitowski switowski.com
  • 40. Virtual environment If pip installs every package in the same folder, why can’t we tell it to temporarily install them in a different folder? Virtual environment: • Creates a special folder with Python binaries • Tells pip to install new packages to that folder • Tells Python to use packages from that folder @SebaWitowski switowski.com
  • 41. Using virtual environments 1. Create new virtual environment $ python -m venv .venv @SebaWitowski switowski.com
  • 42. Using virtual environments 1. Create new virtual environment 2. Activate it $ source .venv/bin/activate @SebaWitowski switowski.com
  • 43. Using virtual environments 1. Create new virtual environment 2. Activate it $ source .venv/bin/activate # Your prompt should change: (venv) $ @SebaWitowski switowski.com
  • 44. Using virtual environments 1. Create new virtual environment 2. Activate it 3. Work on your Python project (install packages, run Python) (venv) $ pip install Django==2.2 ... (venv) $ python manage.py runserver @SebaWitowski switowski.com
  • 45. Using virtual environments 1. Create new virtual environment 2. Activate it 3. Work on your Python project (install packages, run Python) 4. Deactivate virtual environment to stop using it (venv) $ deactivate $ @SebaWitowski switowski.com
  • 46. Typical workflow # Inside Django 3 project folder $ python -m venv django3-app $ source django3-app/bin/activate $ pip install django==3.0 # Inside Django 2 project folder $ python -m venv django2-app $ source django2-app/bin/activate $ pip install django==2.2 @SebaWitowski switowski.com
  • 48. virtualenvwrapper virtualenvwrapper stores all virtual environments in: ~/.virtualenvs/ @SebaWitowski switowski.com
  • 49. virtualenvwrapper virtualenvwrapper stores all virtual environments in: ~/.virtualenvs/ $ mkvirtualenv django2-app - create a virtual environment $ workon django2-app - activate it $ lsvirtualenv - list all virtual environments $ rmvirtualenv django2-app - delete a virtual environment @SebaWitowski switowski.com
  • 51. Global Python packages • Some tools should be installed globally (black, flake8, virtualenvwrapper) @SebaWitowski switowski.com
  • 52. Global Python packages • Some tools should be installed globally (black, flake8, virtualenvwrapper) • But if they require different versions of the same dependency, one of them will break @SebaWitowski switowski.com
  • 53. Global Python packages • Some tools should be installed globally (black, flake8, virtualenvwrapper) • But if they require different versions of the same dependency, one of them will break • Installing global tools into separate virtual environments is a hassle (you have to activate each virtual environment to use that tool) @SebaWitowski switowski.com
  • 54. pipx - global packages in separate environments https://github.com/pipxproject/pipx @SebaWitowski switowski.com
  • 55. pipx in action 1. Install “black” package $ pipx install black installed package black 20.8b1, Python 3.8.5 These apps are now globally available - black - black-primer - blackd done! ✨ 🌟 ✨ @SebaWitowski switowski.com
  • 56. pipx in action 1. Install “black” package 2. Use black $ black hello_world.py reformatted hello_world.py All done! ✨ 🍰 ✨ 1 file reformatted. @SebaWitowski switowski.com
  • 57. pipx in action 1. Install “black” package 2. Use black 3. “black” installed in a virtual env will shadow the global one # Inside a virtual environment (venv) $ black --version black, version 19.3b0 # Outside of a virtual environment $ black --version black, version 20.8b1 @SebaWitowski switowski.com
  • 58. pipx commands $ pipx list - list all installed packages $ pipx uninstall <package> - uninstall package $ pipx upgrade-all - upgrade all packages $ pipx inject pytest pytest-cov - install pytest-cov inside pytest virtual env @SebaWitowski switowski.com
  • 59. Dependencies in your project @SebaWitowski switowski.com
  • 60. Dependencies in your project # requirements.txt Django django-redis pytest @SebaWitowski switowski.com
  • 61. Dependencies in your project # requirements.txt Django django-redis pytest $ pip install -r requirements.txt ... Successfully installed Django-2.2, ... @SebaWitowski switowski.com
  • 62. Dependencies in your project # requirements.txt Django django-redis pytest $ pip install -r requirements.txt ... Successfully installed Django-2.2, ... $ pip install -r requirements.txt ... Successfully installed Django-3.0, ... One month later…
  • 63. Dependencies in your project # requirements.txt Django django-redis pytest $ pip install -r requirements.txt ... Successfully installed Django-2.2, ... $ pip install -r requirements.txt ... Successfully installed Django-3.0, ... One month later…
  • 64. Dependencies in your project # requirements.txt Django>=2.2,<3.0 django-redis==4.12.0 pytest==5.* Dependency pinning: @SebaWitowski switowski.com
  • 65. Dependencies in your project Always pin dependencies on production servers! @SebaWitowski switowski.com
  • 66. Dependencies in your project Always pin dependencies on production servers! And their sub-dependencies (3rd party packages)! @SebaWitowski switowski.com
  • 67. Dependencies in your project Always pin dependencies on production servers! And their sub-dependencies (3rd party packages)! And don’t forget to update packages regularly! @SebaWitowski switowski.com
  • 68. Dependencies in your project Always pin dependencies on production servers! And their sub-dependencies (3rd party packages)! And don’t forget to update packages regularly! That’s a lot of work! @SebaWitowski switowski.com
  • 69. Pipenv and Poetry to the rescue!
  • 70. But do you really need them? @SebaWitowski switowski.com
  • 71. But do you really need them? • What if they stop working? @SebaWitowski switowski.com
  • 72. But do you really need them? • What if they stop working? • What if they get discontinued? @SebaWitowski switowski.com
  • 73. But do you really need them? • What if they stop working? • What if they get discontinued? • Do you really use ALL their features? @SebaWitowski switowski.com
  • 74. Pipenv and Poetry are great @SebaWitowski switowski.com
  • 75. But sometimes a simpler tool is enough Pipenv and Poetry are great @SebaWitowski switowski.com
  • 76. But sometimes a simpler tool is enough Pipenv and Poetry are great https://github.com/jazzband/pip-tools @SebaWitowski switowski.com
  • 78. pip-compile # requirements.in Django>=2.2>,<3.0 pytest # requirements.txt # # This file is autogenerated by pip-compile # To update, run: # # pip-compile requirements.in # attrs==20.2.0 # via pytest django==2.2.17 # via -r requirements.in importlib-metadata==2.0.0 # via pluggy, pytest iniconfig==1.1.1 # via pytest packaging==20.4 # via pytest pluggy==0.13.1 # via pytest py==1.9.0 # via pytest pyparsing==2.4.7 # via packaging pytest==6.1.2 # via -r requirements.in pytz==2020.4 # via django six==1.15.0 # via packaging sqlparse==0.4.1 # via django toml==0.10.2 # via pytest zipp==3.4.0 # via importlib-metadata $ pip-compile requirements.in
  • 79. pip-compile # requirements.txt # # This file is autogenerated by pip-compile # To update, run: # # pip-compile requirements.in # attrs==20.2.0 # via pytest django==2.2.17 # via -r requirements.in importlib-metadata==2.0.0 # via pluggy, pytest iniconfig==1.1.1 # via pytest packaging==20.4 # via pytest pluggy==0.13.1 # via pytest py==1.9.0 # via pytest pyparsing==2.4.7 # via packaging pytest==6.1.2 # via -r requirements.in pytz==2020.4 # via django six==1.15.0 # via packaging sqlparse==0.4.1 # via django toml==0.10.2 # via pytest zipp==3.4.0 # via importlib-metadata @SebaWitowski switowski.com
  • 80. pip-compile # requirements.txt # # This file is autogenerated by pip-compile # To update, run: # # pip-compile requirements.in # attrs==20.2.0 # via pytest django==2.2.17 # via -r requirements.in importlib-metadata==2.0.0 # via pluggy, pytest iniconfig==1.1.1 # via pytest packaging==20.4 # via pytest pluggy==0.13.1 # via pytest py==1.9.0 # via pytest pyparsing==2.4.7 # via packaging pytest==6.1.2 # via -r requirements.in pytz==2020.4 # via django six==1.15.0 # via packaging sqlparse==0.4.1 # via django toml==0.10.2 # via pytest zipp==3.4.0 # via importlib-metadata @SebaWitowski switowski.com
  • 81. pip-compile # requirements.txt # # This file is autogenerated by pip-compile # To update, run: # # pip-compile requirements.in # attrs==20.2.0 # via pytest django==2.2.17 # via -r requirements.in importlib-metadata==2.0.0 # via pluggy, pytest iniconfig==1.1.1 # via pytest packaging==20.4 # via pytest pluggy==0.13.1 # via pytest py==1.9.0 # via pytest pyparsing==2.4.7 # via packaging pytest==6.1.2 # via -r requirements.in pytz==2020.4 # via django six==1.15.0 # via packaging sqlparse==0.4.1 # via django toml==0.10.2 # via pytest zipp==3.4.0 # via importlib-metadata @SebaWitowski switowski.com
  • 82. pip-compile # requirements.txt # # This file is autogenerated by pip-compile # To update, run: # # pip-compile requirements.in # attrs==20.2.0 # via pytest django==2.2.17 # via -r requirements.in importlib-metadata==2.0.0 # via pluggy, pytest iniconfig==1.1.1 # via pytest packaging==20.4 # via pytest pluggy==0.13.1 # via pytest py==1.9.0 # via pytest pyparsing==2.4.7 # via packaging pytest==6.1.2 # via -r requirements.in pytz==2020.4 # via django six==1.15.0 # via packaging sqlparse==0.4.1 # via django toml==0.10.2 # via pytest zipp==3.4.0 # via importlib-metadata @SebaWitowski switowski.com
  • 83. pip-compile # requirements.txt # # This file is autogenerated by pip-compile # To update, run: # # pip-compile requirements.in # attrs==20.2.0 # via pytest django==2.2.17 # via -r requirements.in importlib-metadata==2.0.0 # via pluggy, pytest iniconfig==1.1.1 # via pytest packaging==20.4 # via pytest pluggy==0.13.1 # via pytest py==1.9.0 # via pytest pyparsing==2.4.7 # via packaging pytest==6.1.2 # via -r requirements.in pytz==2020.4 # via django six==1.15.0 # via packaging sqlparse==0.4.1 # via django toml==0.10.2 # via pytest zipp==3.4.0 # via importlib-metadata @SebaWitowski switowski.com
  • 84. pip-compile Now, run: $ pip install -r requirements.txt @SebaWitowski switowski.com
  • 85. pip-compile Now, run: $ pip install -r requirements.txt Need to update dependencies? $ pip-compile requirements.in @SebaWitowski switowski.com
  • 86. pip-compile Make pip-compile part of your CI @SebaWitowski switowski.com
  • 87. pip-compile Make pip-compile part of your CI If something breaks, pin that package in requirements.in @SebaWitowski switowski.com
  • 91. Summary • Use pyenv to install/update Python versions @SebaWitowski switowski.com
  • 92. Summary • Use pyenv to install/update Python versions • Use venv/virtualenvwrapper to isolate dependencies of your projects @SebaWitowski switowski.com
  • 93. Summary • Use pyenv to install/update Python versions • Use venv/virtualenvwrapper to isolate dependencies of your projects • Use pipx to install global tools @SebaWitowski switowski.com
  • 94. Summary • Use pyenv to install/update Python versions • Use venv/virtualenvwrapper to isolate dependencies of your projects • Use pipx to install global tools • Consider pip-tools when you just need to pin dependencies @SebaWitowski switowski.com
  • 95. Where to go next? @SebaWitowski switowski.com
  • 96. Where to go next? “Modern Python Projects” workshop (part of this conference) @SebaWitowski switowski.com
  • 97. Where to go next? “Modern Python Projects” online course https://modernpythonprojects.com/ @SebaWitowski switowski.com