Skip to content

Instantly share code, notes, and snippets.

@leesahanders
Last active April 30, 2024 02:35
Show Gist options
  • Save leesahanders/1b9aef42f91a1225d0fd6236b7527e89 to your computer and use it in GitHub Desktop.
Save leesahanders/1b9aef42f91a1225d0fd6236b7527e89 to your computer and use it in GitHub Desktop.
Python is hard

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment