从 Pipfile 安装 Pipenv 失败但可以从命令行运行

Pipenv install from Pipfile fails but works from command line

我已经愉快地使用 pipenv 几个月了,但是今天我弄坏了一些东西,我无法弄清楚是什么。当我试图让 line_profiler 工作时,一切都开始了。 It doesn't work with pip at the moment 所以我试着按照自述文件中的说明进行操作。最后这没有用,因为我无法弄清楚如何从 brew.

安装 cython

症状 如果我创建一个新目录,并执行一个像 pipenv install pandas 这样的简单命令,一切正常,我得到一个 Pipfile,如下所示:

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

[dev-packages]

[packages]
pandas = "*"

[requires]
python_version = "3.7"

如果我随后将此 Pipfile 复制到一个新目录并尝试使用 pipenv install 在那里创建一个虚拟环境,它会失败并显示此消息:

✘ 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.

如果我转到我以前工作的目录之一并尝试 pipenv run jupyter notebook,我会收到这样的错误:

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

我已经尝试卸载并重新安装 pipenv,加上 pipenv --rm 和删除缓存的常用技巧 ~/Library/Caches/pipenv

知道我还能检查什么,或者可能会发生什么吗?

我现在可以正常使用了。我承认这不是一个很好的答案,但它可能会对某人有所帮助。我不确定流程的哪一部分是关键的,什么是偶然的:

  • 我发现 ssl 库无法使用基本 pip。这导致我重新安装使用 pyenv 安装的 Python 版本。 pip然后工作。
  • 我从 brew 卸载了 pipenv 的版本,然后使用 pip install.
  • 重新安装了它

所以基本上,重新安装我所有的 python 工具似乎可以解决问题。