jiansoung / issues-list

记录日常学习和开发遇到的问题。欢迎评论交流:)
https://github.com/jiansoung/issues-list/issues
MIT License
14 stars 0 forks source link

pyenv + pipenv quick tutorial #3

Open jiansoung opened 5 years ago

jiansoung commented 5 years ago

pyenv + pipenv quick tutorial

Python Development Workflow with Pyenv + Pipenv

Prerequisites

Install Python with pyenv instead of Hombrew (if you use macOS).

NOTE: Do all the following commands in your own project directory.

STEP ONE

Set the shell-specific Python version:

$ pyenv shell 3.6.6

STEP TWO

  1. Downgrade pip to 18.0
  2. Install pipenv
  3. Create a new project using Python 3.6
  4. Downgrade virtualenv's pip to 18.0

Why downgrade pip to 18.0 ?

jwodder's answer:

This is a bug in pipenv caused by using it alongside the newest version of pip (18.1): https://github.com/pypa/pipenv/issues/2924. You need to downgrade pip — both inside and outside the pipenv environment — to version 18.0 in order for pipenv to work.

ONLY EXECUTE FOLLOWING COMMANDS AT THE CREATION OF YOUR PROJECT

$ pip install --upgrade pip==18.0  # 1
$ pip install pipenv  # 2
$ pipenv install --python 3.6  # 3
$ pipenv run pip install --upgrade pip==18.0  # 4

STEP THREE

Install packages and use the installed packages

$ pipenv install <package>

Now that package is installed, you can use it in your python script. And then you can run your python script using pipenv run:

$ pipenv run python <your script>

Using $ pipenv run ensures that your installed packages are available to your script.

It’s also possible to spawn a new shell that ensures all commands have access to your installed packages with $ pipenv shell.

More

$ pipenv -h

References

  1. https://stackoverflow.com/a/52706841/7950607
  2. Running pipenv gives TypeError: 'module' object is not callable
  3. https://github.com/pypa/pipenv