Skip to content

Instantly share code, notes, and snippets.

@hlombroso
Last active March 12, 2022 03:37
Show Gist options
  • Save hlombroso/96c7f29d5d025564a5fdf3bc8d521dbe to your computer and use it in GitHub Desktop.
Save hlombroso/96c7f29d5d025564a5fdf3bc8d521dbe to your computer and use it in GitHub Desktop.

Tutotial url

https://www.youtube.com/watch?v=zDYL22QNiWk&t=151s

Install pipenv

pip3 install pipenv

Install a package

pipenv install package_name

Activate environment

pipenv shell

Deactive environment

exit

Check version of Python

python --version

Check executable path

python

  • import sys
  • sys.executable
  • quit()

Run command in the environment without activating it

pipenv run python or pipenv run python script.py

Install packages from requirements.txt

pipenv install -r location/to/requirements.txt

Check local packages

pipenv lock -r

Import local packages to requirements.txt file

pipenv lock -r > requirements.txt

Install a package only in a dev environment

pipenv install package_name --dev

Uninstall a package

pipenv uninstall package_name

How to make change in the pipfile

Example change the version of python_version - Open pipfile and change the version (3.7 > 3.6) - recreate the environment by runnning pipenv --python 3.6

Remove a virtual environment

pipenv --rm

Recreate virtual environment from pipfile

pipenv install

Get the path to the virtual environment

pipenv --venv

Check for known security vulnerabilities

pipenv check

Update the version of a package

  • change the version in the pipfile
  • run [pipenv install]

List all the dependencies in a graph

pipenv graph

Set lockfile - before deployment

pipenv lock

Ignore pipfile (while installing on server)

pipenv install --ignore-pipfile

Get path of virtual environment in pipenv

Get Path of the project

pipenv --where

Get path of virtual environment

pipenv --venv

How to push to production

-Update pipfile.lock file: [pipenv lock] -Push pipfile.lock for production -Recreate the virtual environment from pipfile.lock file pipenv install --ignore-pipfile

Set environment variables

  • create a .env file within the project
  • add the variabale to be accessible within the environment SECRET_KEY="MySuperSecretKey"
  • Check the environment variabale pipenv run python
    • import os
    • os.environ['SECRET_KEY']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment