Search code examples
pythonpipenv

Pipenv install from Pipfile fails but works from command line


I have been happily using pipenv for a few months, but today I broke something and I can't work out what. It all started when I tried to get line_profiler to work. It doesn't work with pip at the moment so I tried to follow the instructions in the readme. In this end this didn't work as I couldn't figure out how to get cython to install from brew.

The symptoms If I create a new directory, and do a simple command like pipenv install pandas everything works, and I get a Pipfile that looks like this:

[[source]]
name = "pypi"
url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]

[packages]
pandas = "*"

[requires]
python_version = "3.7"

If I then copy this Pipfile to a new directory and try to create a virtual environment there with pipenv install it fails with this message:

✘ Failed creating virtual environment 
[pipenv.exceptions.VirtualenvCreationException]:   File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/cli/command.py", line 254, in install
[pipenv.exceptions.VirtualenvCreationException]:       editable_packages=state.installstate.editables,
[pipenv.exceptions.VirtualenvCreationException]:   File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/core.py", line 1741, in do_install
[pipenv.exceptions.VirtualenvCreationException]:       pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]:   File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/core.py", line 574, in ensure_project
[pipenv.exceptions.VirtualenvCreationException]:       pypi_mirror=pypi_mirror,
[pipenv.exceptions.VirtualenvCreationException]:   File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/core.py", line 506, in ensure_virtualenv
[pipenv.exceptions.VirtualenvCreationException]:       python=python, site_packages=site_packages, pypi_mirror=pypi_mirror
[pipenv.exceptions.VirtualenvCreationException]:   File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/core.py", line 935, in do_create_virtualenv
[pipenv.exceptions.VirtualenvCreationException]:       extra=[crayons.blue("{0}".format(c.err)),]
[pipenv.exceptions.VirtualenvCreationException]: Traceback (most recent call last):
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/virtualenv.py", line 2502, in <module>
    main()
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/virtualenv.py", line 793, in main
    symlink=options.symlink,
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/virtualenv.py", line 1070, in create_environment
    install_python(home_dir, lib_dir, inc_dir, bin_dir, site_packages=site_packages, clear=clear, symlink=symlink)
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/virtualenv.py", line 1487, in install_python
    shutil.copy(original_python, py_executable)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/shutil.py", line 245, in copy
    copyfile(src, dst, follow_symlinks=follow_symlinks)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/shutil.py", line 103, in copyfile
    if _samefile(src, dst):
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/shutil.py", line 88, in _samefile
    return os.path.samefile(src, dst)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/genericpath.py", line 96, in samefile
    s1 = os.stat(f1)
TypeError: stat: path should be string, bytes, os.PathLike or integer, not NoneType

Failed to create virtual environment.

If I go to one of my previously working directories and try pipenv run jupyter notebook I get an error like this:

pipenv run jupyter notebook
Traceback (most recent call last):
  File "/Users/robertking/.local/share/virtualenvs/decision_quality-DM1iI0uH/bin/jupyter-notebook", line 6, in <module>
    from notebook.notebookapp import main
  File "/Users/robertking/.local/share/virtualenvs/decision_quality-DM1iI0uH/lib/python3.6/site-packages/notebook/notebookapp.py", line 62, in <module>
    from tornado import httpserver
  File "/Users/robertking/.local/share/virtualenvs/decision_quality-DM1iI0uH/lib/python3.6/site-packages/tornado/httpserver.py", line 29, in <module>
    import ssl
  File "/Users/robertking/.pyenv/versions/3.6.8/lib/python3.6/ssl.py", line 101, in <module>
    import _ssl             # if we can't import it, let the error propagate
ImportError: dlopen(/Users/robertking/.local/share/virtualenvs/decision_quality-DM1iI0uH/lib/python3.6/lib-dynload/_ssl.cpython-36m-darwin.so, 2): Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib
  Referenced from: /Users/robertking/.local/share/virtualenvs/decision_quality-DM1iI0uH/lib/python3.6/lib-dynload/_ssl.cpython-36m-darwin.so
  Reason: image not found

I have tried uninstall and re-install of pipenv, plus the usual tricks of pipenv --rm and removing the cache ~/Library/Caches/pipenv

Any idea what else I can check, or what might be happening?


Solution

  • I have things working again now. I acknowledge this isn't a great answer, but it might help someone. I'm not sure exactly which part of the process was critical and what was incidental:

    • I found that the ssl libraries weren't working with basic pip. This led me to reinstall the versions of Python I had installed using pyenv. pip then worked.
    • I uninstalled the version of pipenv I had from brew and reinstalled it using pip install.

    So basically, reinstall all my python tools seemed to sort things out.