Code Monkey home page Code Monkey logo

pipenv's Introduction

Pipenv: Python Development Workflow for Humans

image image CI image


Pipenv is a Python virtualenv management tool that supports a multitude of systems and nicely bridges the gaps between pip, python (using system python, pyenv or asdf) and virtualenv. Linux, macOS, and Windows are all first-class citizens in pipenv.

Pipenv automatically creates and manages a virtualenv for your projects, as well as adds/removes packages from your Pipfile as you install/uninstall packages. It also generates a project Pipfile.lock, which is used to produce deterministic builds.

Pipenv is primarily meant to provide users and developers of applications with an easy method to arrive at a consistent working project environment.

The problems that Pipenv seeks to solve are multi-faceted:

  • You no longer need to use pip and virtualenv separately: they work together.
  • Managing a requirements.txt file with package hashes can be problematic. Pipenv uses Pipfile and Pipfile.lock to separate abstract dependency declarations from the last tested combination.
  • Hashes are documented in the lock file which are verified during install. Security considerations are put first.
  • Strongly encourage the use of the latest versions of dependencies to minimize security risks arising from outdated components.
  • Gives you insight into your dependency graph (e.g. $ pipenv graph).
  • Streamline development workflow by supporting local customizations with .env files.

Table Of Contents

Installation

Pipenv can be installed with Python 3.7 and above.

For most users, we recommend installing Pipenv using pip:

pip install --user pipenv

Or, if you're using Fedora:

sudo dnf install pipenv

Or, if you're using FreeBSD:

pkg install py39-pipenv

Or, if you're using Gentoo:

sudo emerge pipenv

Or, if you're using Void Linux:

sudo xbps-install -S python3-pipenv

Alternatively, some users prefer to use Pipx:

pipx install pipenv

Or, some users prefer to use Python pip module

python -m pip install pipenv

Refer to the documentation for latest instructions.

✨🍰✨

Features

  • Enables truly deterministic builds, while easily specifying only what you want.
  • Generates and checks file hashes for locked dependencies.
  • Automatically install required Pythons, if pyenv or asdf is available.
  • Automatically finds your project home, recursively, by looking for a Pipfile.
  • Automatically generates a Pipfile, if one doesn't exist.
  • Automatically creates a virtualenv in a standard location.
  • Automatically adds/removes packages to a Pipfile when they are installed/uninstalled.
  • Automatically loads .env files, if they exist.

For command reference, see Commands.

Basic Concepts

  • A virtualenv will automatically be created, when one doesn't exist.
  • When no parameters are passed to install, all packages [packages] specified will be installed.
  • Otherwise, whatever virtualenv defaults to will be the default.

Shell Completion

To enable completion in fish, add this to your configuration ~/.config/fish/completions/pipenv.fish:

eval (env _PIPENV_COMPLETE=fish_source pipenv)

There is also a fish plugin, which will automatically activate your subshells for you!

Alternatively, with zsh, add this to your configuration ~/.zshrc:

eval "$(_PIPENV_COMPLETE=zsh_source pipenv)"

Alternatively, with bash, add this to your configuration ~/.bashrc or ~/.bash_profile:

eval "$(_PIPENV_COMPLETE=bash_source pipenv)"

Magic shell completions are now enabled!

Usage

$ pipenv --help
Usage: pipenv [OPTIONS] COMMAND [ARGS]...

Options:
  --where                         Output project home information.
  --venv                          Output virtualenv information.
  --py                            Output Python interpreter information.
  --envs                          Output Environment Variable options.
  --rm                            Remove the virtualenv.
  --bare                          Minimal output.
  --man                           Display manpage.
  --support                       Output diagnostic information for use in
                                  GitHub issues.
  --site-packages / --no-site-packages
                                  Enable site-packages for the virtualenv.
                                  [env var: PIPENV_SITE_PACKAGES]
  --python TEXT                   Specify which version of Python virtualenv
                                  should use.
  --clear                         Clears caches (pipenv, pip).  [env var:
                                  PIPENV_CLEAR]
  -q, --quiet                     Quiet mode.
  -v, --verbose                   Verbose mode.
  --pypi-mirror TEXT              Specify a PyPI mirror.
  --version                       Show the version and exit.
  -h, --help                      Show this message and exit.

Usage Examples:

  Create a new project using Python 3.7, specifically:
  $ pipenv --python 3.7

  Remove project virtualenv (inferred from current directory):
  $ pipenv --rm

  Install all dependencies for a project (including dev):
  $ pipenv install --dev

  Create a lockfile containing pre-releases:
  $ pipenv lock --pre

  Show a graph of your installed dependencies:
  $ pipenv graph

  Check your installed dependencies for security vulnerabilities:
  $ pipenv check

  Install a local setup.py into your virtual environment/Pipfile:
  $ pipenv install -e .

  Use a lower-level pip command:
  $ pipenv run pip freeze

Commands:

  check         Checks for PyUp Safety security vulnerabilities and against
                PEP 508 markers provided in Pipfile.
  clean         Uninstalls all packages not specified in Pipfile.lock.
  graph         Displays currently-installed dependency graph information.
  install       Installs provided packages and adds them to Pipfile, or (if no
                packages are given), installs all packages from Pipfile.
  lock          Generates Pipfile.lock.
  open          View a given module in your editor.
  requirements  Generate a requirements.txt from Pipfile.lock.
  run           Spawns a command installed into the virtualenv.
  scripts       Lists scripts in current environment config.
  shell         Spawns a shell within the virtualenv.
  sync          Installs all packages specified in Pipfile.lock.
  uninstall     Uninstalls a provided package and removes it from Pipfile.
  update        Runs lock, then sync.
  upgrade       Update the lock of the specified dependency / sub-dependency,
                but does not actually install the packages.
  verify        Verify the hash in Pipfile.lock is up-to-date.

Locate the project:

$ pipenv --where
/Users/kennethreitz/Library/Mobile Documents/com~apple~CloudDocs/repos/kr/pipenv/test

Locate the virtualenv:

$ pipenv --venv
/Users/kennethreitz/.local/share/virtualenvs/test-Skyy4vre

Locate the Python interpreter:

$ pipenv --py
/Users/kennethreitz/.local/share/virtualenvs/test-Skyy4vre/bin/python

Install packages:

$ pipenv install
Creating a virtualenv for this project...
...
No package provided, installing all dependencies.
Virtualenv location: /Users/kennethreitz/.local/share/virtualenvs/test-EJkjoYts
Installing dependencies from Pipfile.lock...
...

To activate this project's virtualenv, run the following:
$ pipenv shell

Installing from git:

You can install packages with pipenv from git and other version control systems using URLs formatted according to the following rule:

<vcs_type>+<scheme>://<location>/<user_or_organization>/<repository>@<branch_or_tag>#<package_name>

The only optional section is the @<branch_or_tag> section. When using git over SSH, you may use the shorthand vcs and scheme alias git+git@<location>:<user_or_organization>/<repository>@<branch_or_tag>#<package_name>. Note that this is translated to git+ssh://git@<location> when parsed.

Valid values for <vcs_type> include git, bzr, svn, and hg. Valid values for <scheme> include http,, https, ssh, and file. In specific cases you also have access to other schemes: svn may be combined with svn as a scheme, and bzr can be combined with sftp and lp.

Note that it is strongly recommended that you install any version-controlled dependencies in editable mode, using pipenv install -e, in order to ensure that dependency resolution can be performed with an up to date copy of the repository each time it is performed, and that it includes all known dependencies.

Below is an example usage which installs the git repository located at https://github.com/requests/requests.git from tag v2.19.1 as package name requests:

$ pipenv install -e git+https://github.com/requests/[email protected]#egg=requests
Creating a Pipfile for this project...
Installing -e git+https://github.com/requests/[email protected]#egg=requests...
[...snipped...]
Adding -e git+https://github.com/requests/[email protected]#egg=requests to Pipfile's [packages]...
[...]

You can read more about pip's implementation of vcs support here.

Install a dev dependency:

$ pipenv install pytest --dev
Installing pytest...
...
Adding pytest to Pipfile's [dev-packages]...

Show a dependency graph:

$ pipenv graph
requests==2.18.4
  - certifi [required: >=2017.4.17, installed: 2017.7.27.1]
  - chardet [required: >=3.0.2,<3.1.0, installed: 3.0.4]
  - idna [required: >=2.5,<2.7, installed: 2.6]
  - urllib3 [required: <1.23,>=1.21.1, installed: 1.22]

Generate a lockfile:

$ pipenv lock
Assuring all dependencies from Pipfile are installed...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Note: your project now has only default [packages] installed.
To install [dev-packages], run: $ pipenv install --dev

Install all dev dependencies:

$ pipenv install --dev
Pipfile found at /Users/kennethreitz/repos/kr/pip2/test/Pipfile. Considering this to be the project home.
Pipfile.lock out of date, updating...
Assuring all dependencies from Pipfile are installed...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...

Uninstall everything:

$ pipenv uninstall --all
No package provided, un-installing all dependencies.
Found 25 installed package(s), purging...
...
Environment now purged and fresh!

Use the shell:

$ pipenv shell
Loading .env environment variables...
Launching subshell in virtual environment. Type 'exit' or 'Ctrl+D' to return.
$ β–―

PURPOSE AND ADVANTAGES OF PIPENV

To understand the problems that Pipenv solves, it's useful to show how Python package management has evolved.

Take yourself back to the first Python iteration. We had Python, but there was no clean way to install packages.

Then came Easy Install, a package that installs other Python packages with relative ease. But it came with a catch: it wasn't easy to uninstall packages that were no longer needed.

Enter pip, which most Python users are familiar with. pip lets us install and uninstall packages. We could specify versions, run pip freeze > requirements.txt to output a list of installed packages to a text file, and use that same text file to install everything an app needed with pip install -r requirements.txt.

But pip didn't include a way to isolate packages from each other. We might work on apps that use different versions of the same libraries, so we needed a way to enable that.

Pipenv aims to solve several problems. First, the problem of needing the pip library for package installation, plus a library for creating a virtual environment, plus a library for managing virtual environments, plus all the commands associated with those libraries. That's a lot to manage. Pipenv ships with package management and virtual environment support, so you can use one tool to install, uninstall, track, and document your dependencies and to create, use, and organize your virtual environments. When you start a project with it, Pipenv will automatically create a virtual environment for that project if you aren't already using one.

Pipenv accomplishes this dependency management by abandoning the requirements.txt norm and trading it for a new document called a Pipfile. When you install a library with Pipenv, a Pipfile for your project is automatically updated with the details of that installation, including version information and possibly the Git repository location, file path, and other information.

Second, Pipenv wants to make it easier to manage complex interdependencies.

Using Pipenv, which gives you Pipfile, lets you avoid these problems by managing dependencies for different environments for you. This command will install the main project dependencies:

pipenv install

Adding the --dev tag will install the dev/testing requirements:

pipenv install --dev To generate a Pipfile.lock file, run:

pipenv lock

You can also run Python scripts with Pipenv. To run a top-level Python script called hello.py, run:

pipenv run python hello.py

And you will see your expected result in the console.

To start a shell, run:

pipenv shell

If you would like to convert a project that currently uses a requirements.txt file to use Pipenv, install Pipenv and run:

pipenv install requirements.txt

This will create a Pipfile and install the specified requirements.

Documentation

Documentation resides over at pipenv.pypa.io.

Star History

Star History Chart

pipenv's People

Contributors

altendky avatar cclauss avatar daveschaefer avatar dependabot[bot] avatar dqkqd avatar erinxocon avatar frostming avatar github-actions[bot] avatar glenrsmith avatar greysteil avatar hroncok avatar jacobhayes avatar jayvdb avatar jerempy avatar jtratner avatar jxltom avatar kennethreitz avatar matteius avatar micahjsmith avatar nateprewitt avatar ncoghlan avatar nonylene avatar otherjake avatar oz123 avatar tapaswenipathak avatar techalchemy avatar timofurrer avatar tsiq-oliver avatar uranusjr avatar zbentley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pipenv's Issues

`pipenv install -r requirements.txt` fails with TypeError on pip-compile requirements file

Running pipenv install -r on a requirements.txt file generated by pip-compile gives an error:

$ pipenv install -r requirements.txt
Traceback (most recent call last):
  File "/Users/paul/.pyenv/versions/3.4.4/bin/pipenv", line 9, in <module>
    load_entry_point('pipenv==0.2.4', 'console_scripts', 'pipenv')()
  File "/Users/paul/.pyenv/versions/3.4.4/lib/python3.4/site-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/Users/paul/.pyenv/versions/3.4.4/lib/python3.4/site-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/Users/paul/.pyenv/versions/3.4.4/lib/python3.4/site-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/paul/.pyenv/versions/3.4.4/lib/python3.4/site-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/paul/.pyenv/versions/3.4.4/lib/python3.4/site-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/Users/paul/.pyenv/versions/3.4.4/lib/python3.4/site-packages/pipenv/cli.py", line 345, in install
    package_names = from_requirements_file(r)
  File "/Users/paul/.pyenv/versions/3.4.4/lib/python3.4/site-packages/pipenv/cli.py", line 293, in from_requirements_file
    return [p for p in r.read().split('\n') if p and not p.startswith('#')]
TypeError: 'str' does not support the buffer interface

I've uploaded a gist of the requirements file.

Trailing comments cause parse error in `pipenv install -r requirements.txt`

Running pipenv install -r requirements.txt on a file with trailing comments (such as those generated by pip-compile) gives the following error:

$ pipenv install -r requirements.txt
Installing amqp==2.1.4               # via kombu...

Error:  An error occured while installing amqp==2.1.4               # via kombu
Invalid requirement: 'amqp==2.1.4               # via kombu'
Traceback (most recent call last):
  File "/Users/paul/qwil/backend/.venv/lib/python3.4/site-packages/pip/_vendor/packaging/requirements.py", line 92, in __init__
    req = REQUIREMENT.parseString(requirement_string)
  File "/Users/paul/qwil/backend/.venv/lib/python3.4/site-packages/pip/_vendor/pyparsing.py", line 1617, in parseString
    raise exc
  File "/Users/paul/qwil/backend/.venv/lib/python3.4/site-packages/pip/_vendor/pyparsing.py", line 1607, in parseString
    loc, tokens = self._parse( instring, 0 )
  File "/Users/paul/qwil/backend/.venv/lib/python3.4/site-packages/pip/_vendor/pyparsing.py", line 1379, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/Users/paul/qwil/backend/.venv/lib/python3.4/site-packages/pip/_vendor/pyparsing.py", line 3376, in parseImpl
    loc, exprtokens = e._parse( instring, loc, doActions )
  File "/Users/paul/qwil/backend/.venv/lib/python3.4/site-packages/pip/_vendor/pyparsing.py", line 1383, in _parseNoCache
    loc,tokens = self.parseImpl( instring, preloc, doActions )
  File "/Users/paul/qwil/backend/.venv/lib/python3.4/site-packages/pip/_vendor/pyparsing.py", line 3164, in parseImpl
    raise ParseException(instring, loc, self.errmsg, self)
pip._vendor.pyparsing.ParseException: Expected stringEnd (at char 26), (line:1, col:27)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/paul/qwil/backend/.venv/lib/python3.4/site-packages/pip/req/req_install.py", line 82, in __init__
    req = Requirement(req)
  File "/Users/paul/qwil/backend/.venv/lib/python3.4/site-packages/pip/_vendor/packaging/requirements.py", line 96, in __init__
    requirement_string[e.loc:e.loc + 8]))
pip._vendor.packaging.requirements.InvalidRequirement: Invalid requirement, parse error at "'# via ko'"

Looks like the requirements parser is just skipping lines which startwith('#') but looks like we need to be a bit more cunning to pluck out trailing comments.

--three doesn't work

I have empty directory:

% ls -la
total 0
drwx------ 2 mysz staff - 68 23 sty 08:28 ./
drwxr-xr-x 24 mysz staff - 816 23 sty 08:25 ../

So install some module that requires Py3:

% pipenv --three install fileperms
Creating a Pipfile for this project...
Creating a virtualenv for this project...
New python executable in /Users/mysz/tmp/asd/.venv/bin/python2.7
Also creating executable in /Users/mysz/tmp/asd/.venv/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /Users/mysz/tmp/asd/.venv
Installing fileperms...
Collecting fileperms
Using cached fileperms-1.0.4-py2.py3-none-any.whl
Installing collected packages: fileperms
Successfully installed fileperms-1.0.4

Adding fileperms to Pipfile's [packages]...

Above is line:

New python executable in /Users/mysz/tmp/asd/.venv/bin/python2.7

And in fact, there is virtualenv with python2 instead of python3.

My python3 version:

% python3 --version
Python 3.6.0

Double (pipenv) added to shell?

Notice the shell decoration gets overwritten with pipenv? However if I manually activate from the .venv it works as expected.

17:40:24-rene~/tmp/pipenv$ pipenv shell
Spawning environment shell (/bin/bash).
(pipenv)source /Users/rene/tmp/pipenv/.venv/bin/activate
(pipenv)(pipenv)exit
17:40:35-rene~/tmp/pipenv$ . ./.venv/bin/activate
(pipenv)17:40:47-rene~/tmp/pipenv$ 

The line:

(pipenv)(pipenv)exit

Should be:

(pipenv)17:40:47-rene~/tmp/pipenv$ 

I guess it could be something to do with my setup. Not sure. (osx, homebrew python 3.6).

Alternative installation support / instructions

Many prefer to keep their OS Python install clean of any 3rd party packages.
For others it's not even a choice as they don't have sudo access.

It would be nice to have instructions for an unprivileged user to get pipenv on their PATH in some way.

This seems hacky but it seems to work...

System with Python 3

python3 -m venv ~/bin/_pipenv
source ~/bin/_pipenv/bin/activate
pip install pipenv
ln -s ~/bin/_pipenv/bin/pipenv ~/bin

System with Python2 and virtualenv

virtualenv ~/bin/_pipenv2
source ~/bin/_pipenv2/bin/activate
pip install pipenv
ln -s ~/bin/_pipenv2/bin/pipenv ~/bin/pipenv2

pipfile.lock vs pipfile.freeze

Right now the documentation for Pipfile states the naming conventions are Pipfile and Pipfile.freeze but the current API implementation here is using the original Pipfile.lock. It looks like freeze was the decision in pypa/pipfile#43, but perhaps things have changed since then. It seems like one of the repositories is out of sync with the current naming convention though.

`pip shell` doesn't prepend virtualenv name to bash prompt

For bash shell, when I try activating virtualenv by pip shell, it doesn't prepend virtualenv name before bash prompt.

$ # Global pip
$ pip freeze | wc -l
61
$ pipenv shell
Spawning environment shell (/bin/bash).
$ pip freeze
$ # Means we are inside virtualenv as there is no package
$ which python
/XXXXXX/.venv/bin/python
$ source .venv/bin/activate
(playpipenv) $ 

It might be my bashrc. Will wait till anyone confirms it. Thanks

PermissionError: [Errno 13] Permission denied

sudo pipenv --three

Creating a virtualenv for this project...
Running virtualenv with interpreter /usr/local/opt/python3
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.5/bin/virtualenv", line 11, in <module>
    sys.exit(main())
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/virtualenv.py", line 665, in main
    popen = subprocess.Popen([interpreter, file] + sys.argv[1:], env=env)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 950, in __init__
    restore_signals, start_new_session)
  File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/subprocess.py", line 1540, in _execute_child
    raise child_exception_type(errno_num, err_msg)
PermissionError: [Errno 13] Permission denied

Usage in Docker

What's the best workflow to use Pipenv with Docker?

I am trying to accomplish this with a Django project running inside Docker / Docker Compose.

Any tips / suggestions / ideas?

P.S. also, I am using https://github.com/yyuu/pyenv to automatically activate my virtualenvs and manage local Pythons. Does that not work well with this toolchain?

Run as a module with python -m pipenv

This is something you can do with virtualenv and pip. pipenv is just missing the main.py file to do so.

python3.6 -m venv anenv
. ./anenv/bin/activate
python -m pip install pygame

However pipenv can't run as a module.

$ python3.6 -m pipenv install
/usr/local/opt/python3/bin/python3.6: No module named pipenv.__main__; 'pipenv' is a package and cannot be directly executed

This is useful for running the script with different python interpreters in build scripts and such which use different python versions, or on different platforms where things like "pip3.6" do not exist.

Unable to install `git` URLs with pipenv

Running the command:

zackkitzmiller at Sol in ~/Apps/seatgeek/api on master [?] ⇣
❯ pipenv install git+https://github.com/pyotp/[email protected]                                                                              13:55
Installing git+https://github.com/pyotp/[email protected]...
Collecting git+https://github.com/pyotp/[email protected]
  Cloning https://github.com/pyotp/pyotp.git (to v2.0.1) to /private/var/folders/08/scd34rrx47n2z9b8y88r93kh0000gn/T/pip-0HX3au-build
  Requirement already satisfied (use --upgrade to upgrade): pyotp==2.0.1 from git+https://github.com/pyotp/[email protected] in ./.venv/lib/python2.7/site-packages

Adding git+https://github.com/pyotp/[email protected] to Pipfile's [packages]...

Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 11, in <module>
    sys.exit(cli())
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 697, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 1066, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 895, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/site-packages/click/core.py", line 535, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/pipenv/cli.py", line 374, in install
    project.add_package_to_pipfile(package_name, dev)
  File "/usr/local/lib/python2.7/site-packages/pipenv/project.py", line 91, in add_package_to_pipfile
    data = format_toml(toml.dumps(p))
  File "/usr/local/lib/python2.7/site-packages/toml.py", line 602, in dumps
    addtoretval, addtosections = _dump_sections(sections[section], section)
  File "/usr/local/lib/python2.7/site-packages/toml.py", line 619, in _dump_sections
    if not re.match(r'^[A-Za-z0-9_-]+$', section):
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/re.py", line 141, in match
    return _compile(pattern, flags).match(string)
TypeError: expected string or buffer

The value of p on project.py on line 90:

{u'source': [{u'url': u'https://pypi.org/', u'verify_ssl': True}], u'packages': {u'nose-exclude': u'==0.2.0', u'repoze.lru': u'==0.6', u'Fabric': u'==1.8.3', u'backports.ssl-match-hostname': u'==3.4.0.2', u'Flask': u'==0.10.1', u'boto3': u'==1.4.1', u'fake-factory': u'==0.7.2', u'gevent': u'==1.0.1', u'phpserialize': u'==1.3', u'MySQL-python': u'==1.2.3', u'Werkzeug': u'==0.10.4', u'newrelic': u'==2.60.0.46', u'qrcode': u'==5.1', u'botocore': u'==1.4.12', u'docopt': u'==0.6.2', u'amqp-dispatcher': u'==0.8.0', u'py-bcrypt': u'==0.4', u'fuzzywuzzy': u'==0.2', u'haigha': u'==0.9.0', u'inflector': u'==2.0.11', u'hashids': u'==1.1.0', u'toro': u'==1.0.1', u'six': u'==1.9.0', u'redis': u'==2.10.3', u'suds-jurko': u'==0.6', u'tornado': u'==3.2', u'Sift': u'==3.0.0.0', u'elaphe': u'==0.6.0', u'Jinja2': u'==2.8', u'paramiko': u'==1.12.4', u'Fuzzy': u'==1.0', u'itsdangerous': u'==0.24', u'ndg-httpsclient': u'==0.4.0', u'ecdsa': u'==0.11', u'mock': u'==1.0.0', u'nose_parameterized': u'==0.5.0', u'Unidecode': u'==0.4.9', u'PyYAML': u'==3.11', u'SQLAlchemy': u'==0.6.6', u'gunicorn': u'==18.0', u'factory-boy': u'==2.7.0', u'fakeredis': u'==0.6.2', u'intervaltree': u'==2.1.0', u'urllib3': u'==1.7.1', u'httmock': u'==1.2.3', u'iso8601': u'==0.1.8', u'MarkupSafe': u'==0.23', u'lxml': u'==3.4.1', u'httplib2': u'==0.9', u'coverage': u'==3.7.1', u'python-dateutil': u'==1.5', u'freezegun': u'==0.1.7', u'beautifulsoup4': u'==4.3.2', u'Pillow': u'==2.8.1', u'decorator': u'==3.3.2', u'pika': u'==0.10.0', u'pygeoip': u'==0.2.7', u'ujson': u'==1.34', u'oauth2': u'==1.5.211', u'coveralls': u'==0.5', u'pycurl': u'==7.43.0', u'boto': u'==2.37.0', u'Quadtree': u'==0.1.2', u'pyOpenSSL': u'==0.15.1', u'httpretty': u'==0.8.3', None: {u'git': u'https://github.com/pyotp/pyotp.git', 'ref': u'v2.0.1'}, u'futures': u'==2.1.6', u'timelib': u'==0.2.2', u'mockredispy': u'==2.9.0.9', u'testhttpserver': u'==0.1.4', u'xmltodict': u'==0.8.6', u'python-Levenshtein': u'==0.10.2', u'pytz': u'==2011j', u'greenlet': u'==0.4.7', u'nose': u'==1.3.3', u'statsd': u'==3.2.1', u'paypalrestsdk': u'==1.11.5', u'pycrypto': u'==2.6.1', u'requests': u'==2.4.3', u'raven': u'==5.8.1', u'pyasn1': u'==0.1.9', u'braintree': u'==3.24.0'}}

There is a None key in there.

"pip install pipenv" failure

I run linux Mint and running "pip install pipenv" fails with this error

"""
File "/usr/local/lib/python2.7/dist-packages/pipenv/core.py", line 11, in
import _pipfile as pipfile
ImportError: No module named _pipfile

"""

I had to manually copy the _pipfile directory to my dist-packages/pipenv/ for it to work

Has anyone else experienced this too?

3.6 mac osx homebrew

Hello,

I had these issues with python3.6 on OS X with homebrew python 3.6. It worked with 2.7.

~/tmp/pipenv$ pip3.6 install pipenv
~/tmp/pipenv$ head -1 /usr/local/bin/pipenv 
#!/usr/local/opt/python3/bin/python3.6
~/tmp/pipenv$ pipenv install flask
Creating a Pipfile for this project...
Installing flask...
Requirement already satisfied: flask in ./.venv/lib/python2.7/site-packages
Requirement already satisfied: Jinja2>=2.4 in ./.venv/lib/python2.7/site-packages (from flask)
Requirement already satisfied: Werkzeug>=0.7 in ./.venv/lib/python2.7/site-packages (from flask)
Requirement already satisfied: click>=2.0 in ./.venv/lib/python2.7/site-packages (from flask)
Requirement already satisfied: itsdangerous>=0.21 in ./.venv/lib/python2.7/site-packages (from flask)
Requirement already satisfied: MarkupSafe>=0.23 in ./.venv/lib/python2.7/site-packages (from Jinja2>=2.4->flask)

~/tmp/pipenv$ pipenv shell
Spawning environment shell (/bin/bash).
(pipenv)source /Users/.../tmp/pipenv/.venv/bin/activate
(pipenv)(pipenv)python
Python 2.7.13 (default, Dec 17 2016, 23:03:43) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 

Integrate Pythonz

Right now creating a virtualenv with a custom version of Python is harder than it needs to be: check if you have it installed, if now find the proper way to install it for your OS, then proceed to choose between the exe/conda/ppa/deb/homebrew solution according to your need and the specific version you want, then install and create the virtualenv with the proper command.

pythonz allow you to easily install any Python version. Including legacy ones (2.6) and brand new ones (3.6). pew already integrates it. It would be great to be able to do:

pipenv install foo --python 3.6

And be done with it. It just check if Python 3.6 exists on my machine, and if not, use Pythonz to provide it in my env.

Provide a pipenv temp command

Testing package is a something a Python dev do quite often. But you don't want to install it on your system, so you usually create a virtualenv for that, then discard it.

pew (yes again, sorry to bother you with it) has a command to create a temporary virtualenv. We would do:

pipenv temp

To get into a temporary virtualenv (you and the env being move automatically in the temp dir of your OS), so you can make tests quickly and it get discarded at the next reboot or when you deactivate.

Feature Request - manage dependencies

This is one feature I desperately want. Many times after installing it becomes very difficult to find out dependencies installed by a package and they stay on. If this could be fixed it would be great.

Different python version installed than `which python`

which python points to default mac os 2.7 python but 3.6 was installed.

Here is the output:

➜  m pip3 install pipenv
Collecting pipenv
  Downloading pipe..
Successfully installed click-6.7 colorama-0.3.7 crayons-0.1.1 delegator.py-0.0.6 pexpect-4.2.1 pipenv-0.2.6 ptyprocess-0.5.1 requirements-parser-0.1.0 toml-0.9.2 virtualenv-15.1.0

➜  m pipenv check
Checking PEP 508 requirements...
Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 11, in <module>
    sys.exit(cli())
...
RuntimeError: No Pipfile found!

➜  m pipenv install scrapy
Creating a Pipfile for this project...
Creating a virtualenv for this project...
Using base prefix '/usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/lukas/Documents/python-stuff/m/.venv/bin/python3.6
Also creating executable in /Users/lukas/Documents/python-stuff/m/.venv/bin/python
Installing setuptools, pip, wheel...done.

➜ m python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

➜  m pipenv shell
Spawning environment shell (/bin/zsh).
source /Users/lukas/Documents/python-stuff/m/.venv/bin/activate

➜  m source /Users/lukas/Documents/python-stuff/m/.venv/bin/activate

(m)➜  m python
Python 3.6.0 (default, Dec 24 2016, 00:01:50)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

I'm guessing this could be caused by pip3 -V pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)

Query: Pipfile format

Sorry if this is lame. As a regular user of Bundler in Ruby ecosystem, and package.json from npm, why not use

  • Python, which will give more freedom to express logic and other constructs
  • JSON, as it is human readable and parsers are available already
  • YAML, not as readable as JSON, but saves us from learning one more markup language.

Thanks

pipenv --three , undefined symbol error

btw , do't know why.

[vagrant@dev sync]$ pipenv --three
Creating a virtualenv for this project...
Running virtualenv with interpreter /usr/local/bin/python3
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/virtualenv.py", line 8, in <module>
    import base64
  File "/usr/local/lib/python3.5/base64.py", line 10, in <module>
    import struct
  File "/usr/local/lib/python3.5/struct.py", line 13, in <module>
    from _struct import *
ImportError: /usr/local/lib/python2.7/site-packages/_struct.so: undefined symbol: PyString_AsString

Virtualenv location: /home/vagrant/test/sync/.venv

Thanks

index from requirements.txt isn't working

when there is something like this in requirements.txt:

-i http://my_own_pypi/simple

it's assume it's a package and tries to install it.
I would expect it to add this to the pipfile as a diffrent index (doesn't pipfile support multiple indexes ?)

Configurable virtualenv location

As an mkvirtualenv user, there's one must-have feature that's become really important to me, and that's having a configurable (env variable?) default location for virtualenvs. Personally, I used .local/share/virtualenvs, but that's just a matter of preference.

Having them inside projects (repositories) is a bit annoying since lots of tools won't ignore them, disk-usage is harder to track, and a few other nitpicks.


Note: I'm aware that it may not be the most popular option. I don't mind keeping the current default, but just think that configurability would be nice.

The system cannot find the path specified.

I am using pipenv on windows.
I followed the next steps:

pip install pipenv
mkdir something
cd something
pipenv.exe --two install requests

I am receiving the next error:

Error: An error occured while installing requests
The system cannot find the path specified.

pipenv fails right after install

I have Ubuntu 14.04

installed using pip install pipenv

pipenv producecs stacktrace

Traceback (most recent call last):
  File "/usr/local/bin/pipenv", line 7, in <module>
    from pipenv import cli
  File "/usr/local/lib/python2.7/dist-packages/pipenv/__init__.py", line 1, in <module>
    from .cli import cli
  File "/usr/local/lib/python2.7/dist-packages/pipenv/cli.py", line 9, in <module>
    import delegator
  File "/usr/local/lib/python2.7/dist-packages/delegator.py", line 5, in <module>
    from pexpect.popen_spawn import PopenSpawn
ImportError: No module named popen_spawn

Tried to install popen_spawn manually

Could not find a version that satisfies the requirement popen_spawn (from versions: )
No matching distribution found for popen_spawn

support more shells (fish / csh / bash / powershell)

I'm using fish and looks pipenv works fine without shell command:

❰/private/tmp/asdβ±βœ”β‰» pipenv shell
Spawning virtualenv shell (/usr/local/bin/fish).
Unsupported use of '||'. In fish, please use 'COMMAND; or COMMAND'.
/private/tmp/asd/.venv/bin/activate (line 23):     if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then
                                                                         ^
from sourcing file /private/tmp/asd/.venv/bin/activate
	called on line 194 of file /usr/local/Cellar/fish/2.4.0/share/fish/config.fish

in function '.'
	called on standard input

source: Error while reading file '/private/tmp/asd/.venv/bin/activate'

Seems it is trying to active the virtualenv with bin/active, but virtualenv also support fish via bin/active.fish, i think we can source it while detected current shell is fish.

And also, i think pipenv dose not support csh / cmd.exe now...

Pipenv should use package's original letter case

pipenv install django installs Django, but in the Pipfile it becomes django=*.

$ pipenv install django
Installing django...
Collecting django
  Using cached Django-1.10.5-py2.py3-none-any.whl
Installing collected packages: django
Successfully installed django-1.10.5

Adding django to Pipfile's [packages]...


$ cat Pipfile
[[source]]
url = "https://pypi.org/"
verify_ssl = true

[packages]
Django = "==1.10.5"
django = "*"
$ pipenv install Django
Installing Django...
Collecting Django
  Using cached Django-1.10.5-py2.py3-none-any.whl
Installing collected packages: Django
Successfully installed Django-1.10.5

Adding Django to Pipfile's [packages]...


$ pipenv install django
Installing django...
Requirement already satisfied: django in ./.venv/lib/python3.6/site-packages

Adding django to Pipfile's [packages]...


$ pipenv install djangO
Installing djangO...
Requirement already satisfied: djangO in ./.venv/lib/python3.6/site-packages

Adding djangO to Pipfile's [packages]...


$ cat Pipfile
[[source]]
url = "https://pypi.org/"
verify_ssl = true

[packages]
Django = "*"
django = "*"
djangO = "*"

Fails to create an env using Anaconda prefix

Hey,

nice work - is there any plan to use this as a default in Python?

I have a problem using this though. I have Anaconda installed - when I activate some environment and install pipenv, it fails to create env. Here is full example:

$ source activate mathbs  # my anaconda env
$ pip install pipenv
Collecting pipenv
  Downloading pipenv-0.2.4.tar.gz
...  # truncated
Installing collected packages: colorama, crayons, toml, virtualenv, delegator.py, requirements-parser, pipenv
Successfully installed colorama-0.3.7 crayons-0.1.1 delegator.py-0.0.6 pipenv-0.2.4 requirements-parser-0.1.0 toml-0.9.2 virtualenv-15.1.0
You are using pip version 8.1.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(mathbs) 
dan at 530uarch in ~/tst 
$ pipenv install requests
Creating a Pipfile for this project...
Creating a virtualenv for this project...
Using base prefix '/home/dan/.local/opt/miniconda3/envs/mathbs'
New python executable in /home/dan/tst/.venv/bin/python
/home/dan/tst/.venv/bin/python: error while loading shared libraries: libpython3.5m.so.1.0: cannot open shared object file: No such file or directory
ERROR: The executable /home/dan/tst/.venv/bin/python is not functioning
ERROR: It thinks sys.prefix is '/home/dan/tst' (should be '/home/dan/tst/.venv')
ERROR: virtualenv is not compatible with this system or executable

Virtualenv location: /home/dan/tst/.venv
Installing requests...

Error:  An error occured while installing requests
/bin/sh: /home/dan/tst/.venv/bin/pip: No such file or directory

Some info about the system:

dan at 530uarch in ~/tst 
$ python --version
Python 3.5.1 :: Continuum Analytics, Inc.
(mathbs) 
dan at 530uarch in ~/tst 
$ cat /etc/lsb-release 
LSB_VERSION=1.4
DISTRIB_ID=Arch
DISTRIB_RELEASE=rolling
DISTRIB_DESCRIPTION="Arch Linux"

Pipfile should specify Python version

To reduce friction and the possibility of error when running pipenv install on a project that already has a Pipfile, the Pipfile should specify the Python version. This is already a feature in bundler, where you can specify the Ruby version with the ruby keyword.

Option for skip creating new venv locally

I want to manage my venvs by centralized pyenv-virtualenv so that I can easily share a venv across multiple projects. Is there any chance to add an option for skip creating new venv locally and use current env instead? Thanks!

Better `pipenv --where` output when there is no virtualenv

Presently if I run pipenv --where in a blank directory (i.e no existing virtualenv or Pipfile), the output isn't proper.

$ ll
total 8
drwxrwxr-x 2 XXX XXX 4096 Jan 23 20:19 ./
drwxrwxr-x 7 XXX XXX 4096 Jan 23 19:59 ../
$
$ pipenv --where
Pipfile found at None. Considering this to be the project home.
$ 

`pipenv shell` fails with path including spaces.

tsbertalan@sindri:~$ sudo pip install pipenv
... snip ...
tsbertalan@sindri:~$ cd dirname\ with\ spaces/
tsbertalan@sindri:~/dirname with spaces$ pipenv shell
Creating a Pipfile for this project...
Creating a virtualenv for this project...
New python executable in /home/tsbertalan/dirname with spaces/.venv/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /home/tsbertalan/dirname with spaces/.venv
Spawning environment shell (/bin/bash).
/bin/bash: /home/tsbertalan/dirname: No such file or directory
tsbertalan@sindri:~$ cd dirname\ with\ spaces/
tsbertalan@sindri:~/dirname with spaces$ pipenv shell
Creating a Pipfile for this project...
Creating a virtualenv for this project...
New python executable in /home/tsbertalan/dirname with spaces/.venv/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /home/tsbertalan/dirname with spaces/.venv
Spawning environment shell (/bin/bash).
/bin/bash: /home/tsbertalan/dirname: No such file or directory

Consider using pew to activate virtual environments

I've been using it via the pew package, which fills roughly the same niche as virtualenvwrapper, but using the inve approach. My own experience finds it vastly superior to the script-sourcing approach. Explained simply, it starts a subshell instead of changing the current shell. That means de-activating an environment is as simple as the standard exit command in your shell.

https://gist.github.com/datagrok/2199506
https://github.com/berdario/pew

Provide a way to find required deps from the code

You will not always start with a fresh project. Sometime you will have a project that works but is not cleanly structured and you want to convert it.

Tools like pipreqs allow you to scan your project, find the import of 3rd party tools and turn them into a requirements.txt file.

We can imagine use case for pipenv:

  • pipenv finddeps which does what pipreqs do, but only output it instead of saving it. Using --save would save it in the toml file.
  • pipenv init, which takes a non pipenv project, run findeps in it and then create the toml file with it.

Provide way to run commands without needing to always prepend β€œpipenv run”

I realise right now your tool does not needs to activate any env (I actually like it, it makes it easier for beginers to get in) but I will use pipenv activate eventually.

I would like to suggest to get some inspiration from pew for the virtualenv part. It has some nice benefits:

  • it's pure Python and works with any shell, even in windows. No need for activation script.
  • it spawns a subshell. Meaning you don't activate a virtualenv, you get into a brand new process. To exit the env, you just exist the shell (Ctrl + D). No side effect, back to your previous session.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.