Create a virtual environment:
python3 --version
python3 -m venv .venv
/opt/python/3.7.7/bin/python -m venv .venv
/opt/python/3.9.6/bin/python -m venv .venv
/opt/python/3.9.14/bin/python -m venv .venv
Activate the virtual environment. On Linux or Mac this is done with:
source .venv/bin/activate
On Windows the venv environment is activated with:
venv\Scripts\activate
Upgrade pip and then install needed packages:
python3 -m pip install --upgrade pip wheel setuptools rsconnect-python
python3 -m pip install rsconnect-python
# Set one off configuration to use ppm for pip install
pip install --index-url https://colorado.posit.co/rspm/pypi/latest/simple package-you-want-to-install
python3 -m pip install -r requirements.txt
python3 -m pip install --index-url https://colorado.posit.co/rspm/pypi/latest/simple -r requirements.txt
python3 -m pip install -U fastapi
Here's a requirements.txt example:
--index-url https://packagemanager.rstudio.com/pypi/2023-10-13/simple
numpy==1.23.4
pandas
python-dateutil
pytz
QtPy==2.3.0
tzdata
six
Leave a virtual environment with:
deactivate
We can also write manifest / requirements explicitly:
pip freeze > requirements.txt
rsconnect write-manifest streamlit ~/Projects/streamlit_min/
For me this breaks things for some reason, I need to edit this requirements file explicitly:
# requirements.txt generated by rsconnect-python on 2022-09-21 14:59:58.865441
streamlit==1.11.0
In case it's useful, these rants are marvelous:
- Python packaging pain: https://www.bitecode.dev/p/relieving-your-python-packaging-pain
- This page addresses poetry and conda: https://www.bitecode.dev/p/why-not-tell-people-to-simply-use
- SamE's article on Poetry and Python and Posit products: https://samedwardes.quarto.pub/using-poetry-for-python-dependency-management/#how-do-i-specify-the-source-of-my-packages
- Interesting reports from the scary world of PyPI. Comments in thread https://thehackernews.com/2023/12/116-malware-packages-found-on-pypi.html
- Blog post on venv: https://snarky.ca/how-virtual-environments-work/
- David video on python package issues: https://www.youtube.com/watch?v=hq0sqSZa4Lc
- This has a pretty good rundown on virtualenv vs venv: https://virtualenv.pypa.io/en/latest/
- Shiny for Python talk by Joe Cheng: https://www.youtube.com/watch?v=ijRBbtT2tgc