Where I keep my Python notes for starting projects
brew installwill install at the system level. Sopyenv(the python picker) was done this waypip installwill install into the currently active pyenv python version. So pick this for global things per python version, likepip install pipenv.pipenv installwill install dependencies into the current project.
I use pyenv to manage the operating Python version.
Carefully follow the prerequisites and numbered steps in the Mac install, which starts by using Homebrew.
Then add any requisite lines to the .bashrc file or .zprofile file (it will tell you what to add).
Note that you'll need to restart the shell to make it all work.
Do the Ubuntu install using auto-installer.
On Ubuntu 18.04, before doing the below to install Python 3.7, need to do the following:
sudo apt-get update
sudo apt-get install build-essential libffi-dev libssl-dev libbz2-dev libreadline-dev libsqlite3-dev
pyenv install 3.7.8
pyenv global 3.7.8
pyenv versions
I use pipenv to manage the dependencies for each project. I prefer to keep those dependencies in the project folder, which these steps allow.
I've installed using pip3 install pipenv
Also importantly added export PIPENV_VENV_IN_PROJECT=1 to my .bash_profile
- Start a git repo
- Add
.gitignore - cd into the project
pipenv install jupyterlabpipenv run jupyter lab
or, if not using Jupyter, jut:
pipenv install
NOTE: if you run into lock problems with pipenv, try adding --skip-lock
NOTE: Jupyter notebook and lab both take in the variables from a .env file if it exists, so the below is not needed.
pipenv install python-dotenvThen...
from dotenv import load_dotenv
import os
load_dotenv()
DATABASE_PASSWORD = os.getenv("DATABASE_PASSWORD")Just don't use spaces in the .env file. So:
DATABASE_PASSWORD=`sekrit`Could not import the lzma module. Your installed Python is incomplete. Attempting to use lzma compression will result in a RuntimeError.
I got this from early on with my fresh python install. Looked up the fix and found this:
pip freeze > latestPackages.txtpyenv uninstall 3.7.3brew install xz(This is how you pick up the correct lzma macOS)pyenv install 3.7.3
The brew command said that xz was already installed and up to date. So maybe it wasn't when I first installed python?
With Python 3.8 I couldn't Jupyter Lab to recognize the modules I install in the environment. It's not referencing the kernel.json file in the environment, but looks to a more global version instead.
Jupyter Notebook works, and Jupyter lab works in Python 3.7.7.