最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】Mac本地安装Python3的pipenv虚拟环境

Mac crifan 8856浏览 0评论

折腾:

【已解决】Mac本地用pipenv搭建Flask开发环境

期间,为了在本地开发Flask,先去本地Mac中安装pipenv虚拟环境。

最开始不小心,好像是安装了python2的pipenv了:

Pipenv: Python Dev Workflow for Humans — pipenv 11.10.0 documentation

pipenv 更优雅的管理你的python开发环境 – PyLixm’Wiki – SegmentFault 思否

Pipenv & 虚拟环境 — The Hitchhiker’s Guide to Python

<code>➜  robotDemo python --version
Python 2.7.13
➜  robotDemo which python
/usr/local/bin/python
➜  robotDemo pip --version
pip 9.0.3 from /usr/local/lib/python2.7/site-packages (python 2.7)
➜  robotDemo  python -m site --user-base
/Users/crifan/Library/Python/2.7
</code>

结果报错:

<code>➜  robotDemo pip install --user pipenv
Collecting pipenv
  Downloading https://files.pythonhosted.org/packages/bf/e3/1615d03e17d1ad551a7dad967e5061f30c4ab29e53fe3ad5e8e88e297424/pipenv-11.10.0.tar.gz (5.2MB)
    0% |▏                               | 30kB 1.3kB/s eta 1:04:34Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/usr/local/lib/python2.7/site-packages/pip/commands/install.py", line 335, in run
    wb.build(autobuilding=True)
  File "/usr/local/lib/python2.7/site-packages/pip/wheel.py", line 749, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 380, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/local/lib/python2.7/site-packages/pip/req/req_set.py", line 620, in _prepare_file
    session=self.session, hashes=hashes)
  File "/usr/local/lib/python2.7/site-packages/pip/download.py", line 821, in unpack_url
    hashes=hashes
  File "/usr/local/lib/python2.7/site-packages/pip/download.py", line 659, in unpack_http_url
    hashes)
  File "/usr/local/lib/python2.7/site-packages/pip/download.py", line 882, in _download_http_url
    _download_url(resp, link, content_file, hashes)
  File "/usr/local/lib/python2.7/site-packages/pip/download.py", line 603, in _download_url
    hashes.check_against_chunks(downloaded_chunks)
  File "/usr/local/lib/python2.7/site-packages/pip/utils/hashes.py", line 46, in check_against_chunks
    for chunk in chunks:
  File "/usr/local/lib/python2.7/site-packages/pip/download.py", line 571, in written_chunks
    for chunk in chunks:
  File "/usr/local/lib/python2.7/site-packages/pip/utils/ui.py", line 139, in iter
    for x in it:
  File "/usr/local/lib/python2.7/site-packages/pip/download.py", line 560, in resp_read
    decode_content=False):
  File "/usr/local/lib/python2.7/site-packages/pip/_vendor/urllib3/response.py", line 436, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "/usr/local/lib/python2.7/site-packages/pip/_vendor/urllib3/response.py", line 401, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "/usr/local/Cellar/python/2.7.13/Frameworks/Python.framework/Versions/2.7/lib/python2.7/contextlib.py", line 35, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python2.7/site-packages/pip/_vendor/urllib3/response.py", line 316, in _error_catcher
    raise ReadTimeoutError(self._pool, None, 'Read timed out.')
ReadTimeoutError: HTTPSConnectionPool(host='files.pythonhosted.org', port=443): Read timed out.
You are using pip version 9.0.3, however version 10.0.0 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
</code>

先去升级pip:

<code>➜  robotDemo pip install --upgrade pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/62/a1/0d452b6901b0157a0134fd27ba89bf95a857fbda64ba52e1ca2cf61d8412/pip-10.0.0-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 825kB/s
Installing collected packages: pip
  Found existing installation: pip 9.0.3
    Uninstalling pip-9.0.3:
      Successfully uninstalled pip-9.0.3
Successfully installed pip-10.0.0
</code>

继续:

<code>➜  robotDemo pip install --user pipenv
Collecting pipenv
  Downloading https://files.pythonhosted.org/packages/bf/e3/1615d03e17d1ad551a7dad967e5061f30c4ab29e53fe3ad5e8e88e297424/pipenv-11.10.0.tar.gz (5.2MB)
    100% |████████████████████████████████| 5.2MB 4.2MB/s
Requirement already satisfied: pip&gt;=9.0.1 in /usr/local/lib/python2.7/site-packages (from pipenv) (10.0.0)
Requirement already satisfied: certifi in /usr/local/lib/python2.7/site-packages (from pipenv) (2017.11.5)
Collecting setuptools&gt;=36.2.1 (from pipenv)
  Downloading https://files.pythonhosted.org/packages/20/d7/04a0b689d3035143e2ff288f4b9ee4bf6ed80585cc121c90bfd85a1a8c2e/setuptools-39.0.1-py2.py3-none-any.whl (569kB)
    100% |████████████████████████████████| 573kB 4.7MB/s
Collecting virtualenv-clone&gt;=0.2.5 (from pipenv)
  Downloading https://files.pythonhosted.org/packages/6d/c2/dccb5ccf599e0c5d1eea6acbd058af7a71384f9740179db67a9182a24798/virtualenv_clone-0.3.0-py2.py3-none-any.whl
Requirement already satisfied: virtualenv in /usr/local/lib/python2.7/site-packages (from pipenv) (15.1.0)
Collecting pathlib2==2.1.0; python_version &lt; "3.4" (from pipenv)
  Downloading https://files.pythonhosted.org/packages/b8/1b/02efe53150500722d1b5bbe3d9dd5a417fe07df05566595cf9114ced3c39/pathlib2-2.1.0-py2.py3-none-any.whl
Requirement already satisfied: requests[security]; python_version &lt; "3.0" in /usr/local/lib/python2.7/site-packages (from pipenv) (2.18.4)
Collecting ordereddict; python_version &lt; "3.0" (from pipenv)
  Downloading https://files.pythonhosted.org/packages/53/25/ef88e8e45db141faa9598fbf7ad0062df8f50f881a36ed6a0073e1572126/ordereddict-1.1.tar.gz
Requirement already satisfied: six in /usr/local/lib/python2.7/site-packages (from pathlib2==2.1.0; python_version &lt; "3.4"-&gt;pipenv) (1.10.0)
Requirement already satisfied: chardet&lt;3.1.0,&gt;=3.0.2 in /usr/local/lib/python2.7/site-packages (from requests[security]; python_version &lt; "3.0"-&gt;pipenv) (3.0.4)
Requirement already satisfied: idna&lt;2.7,&gt;=2.5 in /usr/local/lib/python2.7/site-packages (from requests[security]; python_version &lt; "3.0"-&gt;pipenv) (2.6)
Requirement already satisfied: urllib3&lt;1.23,&gt;=1.21.1 in /usr/local/lib/python2.7/site-packages (from requests[security]; python_version &lt; "3.0"-&gt;pipenv) (1.22)
Requirement already satisfied: cryptography&gt;=1.3.4; extra == "security" in /usr/local/lib/python2.7/site-packages (from requests[security]; python_version &lt; "3.0"-&gt;pipenv) (2.1.4)
Requirement already satisfied: pyOpenSSL&gt;=0.14; extra == "security" in /usr/local/lib/python2.7/site-packages (from requests[security]; python_version &lt; "3.0"-&gt;pipenv) (17.5.0)
Requirement already satisfied: cffi&gt;=1.7; platform_python_implementation != "PyPy" in /usr/local/lib/python2.7/site-packages (from cryptography&gt;=1.3.4; extra == "security"-&gt;requests[security]; python_version &lt; "3.0"-&gt;pipenv) (1.11.2)
Requirement already satisfied: enum34; python_version &lt; "3" in /usr/local/lib/python2.7/site-packages (from cryptography&gt;=1.3.4; extra == "security"-&gt;requests[security]; python_version &lt; "3.0"-&gt;pipenv) (1.1.6)
Requirement already satisfied: asn1crypto&gt;=0.21.0 in /usr/local/lib/python2.7/site-packages (from cryptography&gt;=1.3.4; extra == "security"-&gt;requests[security]; python_version &lt; "3.0"-&gt;pipenv) (0.24.0)
Requirement already satisfied: ipaddress; python_version &lt; "3" in /usr/local/lib/python2.7/site-packages (from cryptography&gt;=1.3.4; extra == "security"-&gt;requests[security]; python_version &lt; "3.0"-&gt;pipenv) (1.0.19)
Requirement already satisfied: pycparser in /usr/local/lib/python2.7/site-packages (from cffi&gt;=1.7; platform_python_implementation != "PyPy"-&gt;cryptography&gt;=1.3.4; extra == "security"-&gt;requests[security]; python_version &lt; "3.0"-&gt;pipenv) (2.18)
Building wheels for collected packages: pipenv, ordereddict
  Running setup.py bdist_wheel for pipenv ... done
  Stored in directory: /Users/crifan/Library/Caches/pip/wheels/0d/bc/95/9d9caefa25215e93f3c7f9ab6cb3fe27c4b64626e99bc9bde4
  Running setup.py bdist_wheel for ordereddict ... done
  Stored in directory: /Users/crifan/Library/Caches/pip/wheels/78/d3/a8/9f52c7a389a0ffba6f575a3886b5f7a55461fb6ec34aa5fd38
Successfully built pipenv ordereddict
Installing collected packages: setuptools, virtualenv-clone, pathlib2, ordereddict, pipenv
  The script virtualenv-clone is installed in '/Users/crifan/Library/Python/2.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  The scripts pewtwo, pipenv and pipenv-resolver are installed in '/Users/crifan/Library/Python/2.7/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed ordereddict-1.1 pathlib2-2.1.0 pipenv-11.10.0 setuptools-39.0.1 virtualenv-clone-0.3.0
</code>

但是发现好像应该安装Python3的pipenv:

https://segmentfault.com/a/1190000012837890

“作者推荐在python3下边安装,会提高与virtualenv的兼容性。”

但是此处默认好像是用python2安装的。

http://www.dongwm.com/archives/使用pipenv管理你的项目/

“brew install python3  # 如果已经安装了可以忽略”

去找找,此处的记得之前安装过Python3的,查查之前是否安装,已经安装的版本:

【已解决】Mac中用brew查看之前已安装过的Python3的信息

那就去用python3去安装试试:

先重新安装python3中的pip

<code>➜  robotDemo python3 -m pip install --upgrade --force-reinstall pip
Collecting pip
  Downloading https://files.pythonhosted.org/packages/62/a1/0d452b6901b0157a0134fd27ba89bf95a857fbda64ba52e1ca2cf61d8412/pip-10.0.0-py2.py3-none-any.whl (1.3MB)
    100% |████████████████████████████████| 1.3MB 746kB/s
Installing collected packages: pip
  Found existing installation: pip 9.0.3
    Uninstalling pip-9.0.3:
      Successfully uninstalled pip-9.0.3
Successfully installed pip-10.0.0
</code>

然后顺带看看pip3:

<code>➜  robotDemo which pip3
/usr/local/bin/pip3
➜  robotDemo ll /usr/local/bin/pip*
-rwxr-xr-x  1 crifan  admin   235B  4 17 11:05 /usr/local/bin/pip
-rwxr-xr-x  1 crifan  admin   235B  4 17 10:18 /usr/local/bin/pip2
-rwxr-xr-x  1 crifan  admin   235B  4 17 10:18 /usr/local/bin/pip2.7
lrwxr-xr-x  1 crifan  admin    33B  4 17 10:52 /usr/local/bin/pip3 -&gt; ../Cellar/python/3.6.4_4/bin/pip3
lrwxr-xr-x  1 crifan  admin    35B  4 17 10:52 /usr/local/bin/pip3.6 -&gt; ../Cellar/python/3.6.4_4/bin/pip3.6
➜  robotDemo pip3 --version
pip 10.0.0 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
</code>

以用户模式安装pipenv:

<code>  robotDemo pip3 install pipenv --user
Collecting pipenv
  Downloading https://files.pythonhosted.org/packages/e5/fd/740a41c68c38262265d73191fb686f38d26c4ea1ea6080a65b2b626bedc7/pipenv-11.10.0-py3-none-any.whl (5.6MB)
    100% |████████████████████████████████| 5.6MB 3.3MB/s
Requirement already satisfied: setuptools&gt;=36.2.1 in /usr/local/lib/python3.6/site-packages (from pipenv) (38.5.2)
Collecting virtualenv (from pipenv)
  Downloading https://files.pythonhosted.org/packages/ed/ea/e20b5cbebf45d3096e8138ab74eda139595d827677f38e9dd543e6015bdf/virtualenv-15.2.0-py2.py3-none-any.whl (2.6MB)
    100% |████████████████████████████████| 2.6MB 8.6MB/s
Collecting certifi (from pipenv)
  Downloading https://files.pythonhosted.org/packages/7c/e6/92ad559b7192d846975fc916b65f667c7b8c3a32bea7372340bfe9a15fa5/certifi-2018.4.16-py2.py3-none-any.whl (150kB)
    100% |████████████████████████████████| 153kB 8.1MB/s
Collecting virtualenv-clone&gt;=0.2.5 (from pipenv)
  Cache entry deserialization failed, entry ignored
  Downloading https://files.pythonhosted.org/packages/6d/c2/dccb5ccf599e0c5d1eea6acbd058af7a71384f9740179db67a9182a24798/virtualenv_clone-0.3.0-py2.py3-none-any.whl
Requirement already satisfied: pip&gt;=9.0.1 in /usr/local/lib/python3.6/site-packages (from pipenv) (10.0.0)
Installing collected packages: virtualenv, certifi, virtualenv-clone, pipenv
  The script virtualenv is installed in '/Users/crifan/Library/Python/3.6/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  The script virtualenv-clone is installed in '/Users/crifan/Library/Python/3.6/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
  The scripts pewtwo, pipenv and pipenv-resolver are installed in '/Users/crifan/Library/Python/3.6/bin' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed certifi-2018.4.16 pipenv-11.10.0 virtualenv-15.2.0 virtualenv-clone-0.3.0
</code>

【已解决】pipenv安装后警告:The script virtualenv is installed in which is not on PATH

然后再看看能否找到刚安装的程序了,分别看看版本:

<code>➜  robotDemo pipenv --version
pipenv, version 11.10.0
➜  robotDemo pipenv-resolver --version
Traceback (most recent call last):
  File "/Users/crifan/Library/Python/3.6/bin/pipenv-resolver", line 11, in &lt;module&gt;
    sys.exit(main())
  File "/Users/crifan/Library/Python/3.6/lib/python/site-packages/pipenv/resolver.py", line 71, in main
    sources=project.sources,
  File "/Users/crifan/Library/Python/3.6/lib/python/site-packages/pipenv/project.py", line 620, in sources
    if 'source' in self.parsed_pipfile:
  File "/Users/crifan/Library/Python/3.6/lib/python/site-packages/pipenv/project.py", line 373, in parsed_pipfile
    with open(self.pipfile_location) as f:
TypeError: expected str, bytes or os.PathLike object, not NoneType
➜  robotDemo pipenv-resolver --help
Traceback (most recent call last):
  File "/Users/crifan/Library/Python/3.6/bin/pipenv-resolver", line 11, in &lt;module&gt;
    sys.exit(main())
  File "/Users/crifan/Library/Python/3.6/lib/python/site-packages/pipenv/resolver.py", line 71, in main
    sources=project.sources,
  File "/Users/crifan/Library/Python/3.6/lib/python/site-packages/pipenv/project.py", line 620, in sources
    if 'source' in self.parsed_pipfile:
  File "/Users/crifan/Library/Python/3.6/lib/python/site-packages/pipenv/project.py", line 373, in parsed_pipfile
    with open(self.pipfile_location) as f:
TypeError: expected str, bytes or os.PathLike object, not NoneType
➜  robotDemo pewtwo --version
It seems that you're running pew for the first time
do you want to modify /Users/crifan/.zshrc to source completions and update your prompt? [y/N]
&gt; quit()
It seems that you're running pew for the first time
do you want to modify /Users/crifan/.zshrc to source completions and update your prompt? [y/N]
&gt; ^CTraceback (most recent call last):
  File "/Users/crifan/Library/Python/3.6/bin/pewtwo", line 11, in &lt;module&gt;
    sys.exit(pew())
  File "/Users/crifan/Library/Python/3.6/lib/python/site-packages/pipenv/patched/pew/pew.py", line 765, in pew
    first_run_setup()
  File "/Users/crifan/Library/Python/3.6/lib/python/site-packages/pipenv/patched/pew/pew.py", line 722, in first_run_setup
    update_config_file(rcpath, source_cmd)
  File "/Users/crifan/Library/Python/3.6/lib/python/site-packages/pipenv/patched/pew/pew.py", line 737, in update_config_file
    " update your prompt? [y/N]\n&gt; " % rcpath).lower()
KeyboardInterrupt
➜  robotDemo virtualenv --version
15.2.0
➜  robotDemo virtualenv-clone --version
Usage: virtualenv-clone [options] /path/to/existing/venv /path/to/cloned/venv

virtualenv-clone: error: no such option: --version
</code>

结果是:

pewtwo

pipenv-resolver

virtualenv-clone

都是没有版本的:

而:

  • pipenv: 11.10.0

  • virtualenv:15.2.0

Basic Usage of Pipenv — pipenv 11.10.0 documentation

继续去操作

<code>➜  robotDemo pwd
/Users/crifan/dev/dev_root/company/naturling/projects/robotDemo
➜  robotDemo pipenv install
Creating a virtualenv for this project…
Using /usr/local/opt/python/bin/python3.6 (3.6.4) to create virtualenv…
⠋Already using interpreter /usr/local/opt/python/bin/python3.6
Using base prefix '/usr/local/Cellar/python/3.6.4_4/Frameworks/Python.framework/Versions/3.6'
New python executable in /Users/crifan/.local/share/virtualenvs/robotDemo-HXjMJQEQ/bin/python3.6
Also creating executable in /Users/crifan/.local/share/virtualenvs/robotDemo-HXjMJQEQ/bin/python
Installing setuptools, pip, wheel...done.

Virtualenv location: /Users/crifan/.local/share/virtualenvs/robotDemo-HXjMJQEQ
Creating a Pipfile for this project…
Pipfile.lock not found, creating…
Locking [dev-packages] dependencies…
Locking [packages] dependencies…
Updated Pipfile.lock (625834)!
Installing dependencies from Pipfile.lock (625834)…
  🐍   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
To activate this project's virtualenv, run the following:
 $ pipenv shell
➜  robotDemo
</code>

彩色输出很好看:

<code>➜  robotDemo python --version
Python 2.7.10
➜  robotDemo which python
/usr/bin/python
➜  robotDemo pipenv shell
Spawning environment shell (/bin/zsh). Use 'exit' to leave.
. /Users/crifan/.local/share/virtualenvs/robotDemo-HXjMJQEQ/bin/activate
➜  robotDemo . /Users/crifan/.local/share/virtualenvs/robotDemo-HXjMJQEQ/bin/activate
➜  robotDemo pwd
/Users/crifan/dev/dev_root/company/naturling/projects/robotDemo
➜  robotDemo which python
/Users/crifan/.local/share/virtualenvs/robotDemo-HXjMJQEQ/bin/python
➜  robotDemo python --version
Python 3.6.4
➜  robotDemo
</code>

可见,进入pipenv的shell后,就自动激活了虚拟环境了,python也是用的默认的Python3的版本了(应为是用python3的pip3安装的pipenv)

看看对应生成的文件:

<code>➜  robotDemo ll -lha
total 16
drwxr-xr-x   4 crifan  staff   128B  4 17 13:53 .
drwxr-xr-x  10 crifan  staff   320B  4 17 10:14 ..
-rw-r--r--   1 crifan  staff   145B  4 17 13:53 Pipfile
-rw-r--r--   1 crifan  staff   460B  4 17 13:53 Pipfile.lock
➜  robotDemo cat Pipfile
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"

[packages]

[dev-packages]

[requires]
python_version = "3.6"
➜  robotDemo cat Pipfile.lock
{
    "_meta": {
        "hash": {
            "sha256": "4e55147db217bb4120f6e68cb8cad7bc37011457441ce0eb9d97308315625834"
        },
        "pipfile-spec": 6,
        "requires": {
            "python_version": "3.6"
        },
        "sources": [
            {
                "name": "pypi",
                "url": "https://pypi.python.org/simple",
                "verify_ssl": true
            }
        ]
    },
    "default": {},
    "develop": {}
}
➜  robotDemo
</code>

看看此时的PATH:

<code>➜  robotDemo echo $PATH
/Users/crifan/.local/share/virtualenvs/robotDemo-HXjMJQEQ/bin:/Users/crifan/Library/Python/3.6/bin:/Users/crifan/.nvm/versions/node/v5.4.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
</code>

添加了当前的虚拟环境的路径了。

-》所以前面找python时,找到的是虚拟环境中的python了。

pipenv 新款Python虚拟环境工具详解-刘江的博客

后续,就是普通的,安装/下载模块了:

后面应该是

pipenv install flask

之类的了。

看看当前环境再退出:

<code>➜  robotDemo pipenv --where
/Users/crifan/dev/dev_root/company/naturling/projects/robotDemo
➜  robotDemo pipenv --venv
/Users/crifan/.local/share/virtualenvs/robotDemo-HXjMJQEQ
➜  robotDemo pipenv --py
/Users/crifan/.local/share/virtualenvs/robotDemo-HXjMJQEQ/bin/python
➜  robotDemo pipenv --envs
The following environment variables can be set, to do various things:

  - PIPENV_SHELL_FANCY
  - PIPENV_PYTHON
  - PIPENV_VENV_IN_PROJECT
  - PIPENV_TEST_INDEX
  - PIPENV_COLORBLIND
  - PIPENV_NOSPIN
  - PIPENV_MAX_ROUNDS
  - PIPENV_PIPFILE
  - PIPENV_DEFAULT_PYTHON_VERSION
  - PIPENV_DONT_LOAD_ENV
  - PIPENV_YES
  - PIPENV_MAX_SUBPROCESS
  - PIPENV_MAX_DEPTH
  - PIPENV_NO_INHERIT
  - PIPENV_VIRTUALENV
  - PIPENV_USE_SYSTEM
  - PIPENV_USE_HASHES
  - PIPENV_SKIP_VALIDATION
  - PIPENV_DOTENV_LOCATION
  - PIPENV_HIDE_EMOJIS
  - PIPENV_TIMEOUT
  - PIPENV_INSTALL_TIMEOUT
  - PIPENV_DONT_USE_PYENV
  - PIPENV_SHELL
  - PIPENV_CACHE_DIR

You can learn more at:
http://docs.pipenv.org/advanced/#configuration-with-environment-variables
➜  robotDemo pipenv graph

➜  robotDemo exit
➜  robotDemo which python
/usr/bin/python
</code>

【后记1】

还是为了避免之前安装的python2的pipenv和python3的pipenv互相影响,去删除掉python2的pipenv吧:

<code>➜  robotDemo pip --version
whpip 10.0.0 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
➜  robotDemo which pip
pip: aliased to noglob pip
➜  robotDemo pip uninstall pipenv
Uninstalling pipenv-11.10.0:
  Would remove:
    /Users/crifan/Library/Python/3.6/bin/pewtwo
    /Users/crifan/Library/Python/3.6/bin/pipenv
    /Users/crifan/Library/Python/3.6/bin/pipenv-resolver
    /Users/crifan/Library/Python/3.6/lib/python/site-packages/pipenv-11.10.0.dist-info/*
    /Users/crifan/Library/Python/3.6/lib/python/site-packages/pipenv/*
Proceed (y/n)? y
  Successfully uninstalled pipenv-11.10.0
➜  robotDemo where pipenv
pipenv not found
</code>

好像是把之前的python3的pipenv删除掉了。

所以先去恢复.bashrc的PATH,确认pip和pip3以及python 和python3是没问题的 :

<code>➜  robotDemo source ~/.bashrc
➜  robotDemo echo $PATH
/Users/crifan/.nvm/versions/node/v5.4.1/bin:/Users/crifan/Library/Python/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
➜  robotDemo vi ~/.bashrc
➜  robotDemo cat ~/.bashrc

export NVM_DIR="/Users/crifan/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] &amp;&amp; . "$NVM_DIR/nvm.sh"  # This loads nvm


➜  robotDemo source ~/.bashrc
➜  robotDemo echo $PATH
/Users/crifan/.nvm/versions/node/v5.4.1/bin:/Users/crifan/Library/Python/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
➜  robotDemo ll /Users/crifan/Library/Python/3.6/bin
total 16
-rwxr-xr-x  1 crifan  staff   232B  4 17 11:06 virtualenv
-rwxr-xr-x  1 crifan  staff   237B  4 17 11:06 virtualenv-clone

➜  robotDemo which pip
pip: aliased to noglob pip
➜  robotDemo which pip3
/usr/local/bin/pip3
➜  robotDemo pip --version
pip 10.0.0 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
➜  robotDemo pip3 --version
pip 10.0.0 from /usr/local/lib/python3.6/site-packages/pip (python 3.6)
➜  robotDemo which python
/usr/bin/python
➜  robotDemo pyton --version
zsh: command not found: pyton
➜  robotDemo python --version
Python 2.7.10
➜  robotDemo which python3
/usr/local/bin/python3
➜  robotDemo python3 --version
Python 3.6.4
</code>

重新安装:

<code>➜  robotDemo pip3 install pipenv --user
Collecting pipenv
  Downloading https://files.pythonhosted.org/packages/e5/fd/740a41c68c38262265d73191fb686f38d26c4ea1ea6080a65b2b626bedc7/pipenv-11.10.0-py3-none-any.whl (5.6MB)
    100% |████████████████████████████████| 5.6MB 2.6MB/s
Requirement already satisfied: virtualenv-clone&gt;=0.2.5 in /Users/crifan/Library/Python/3.6/lib/python/site-packages (from pipenv) (0.3.0)
Requirement already satisfied: certifi in /Users/crifan/Library/Python/3.6/lib/python/site-packages (from pipenv) (2018.4.16)
Requirement already satisfied: setuptools&gt;=36.2.1 in /usr/local/lib/python3.6/site-packages (from pipenv) (38.5.2)
Requirement already satisfied: pip&gt;=9.0.1 in /usr/local/lib/python3.6/site-packages (from pipenv) (10.0.0)
Requirement already satisfied: virtualenv in /Users/crifan/Library/Python/3.6/lib/python/site-packages (from pipenv) (15.2.0)
Installing collected packages: pipenv
Successfully installed pipenv-11.10.0

➜  robotDemo ll -lha /Users/crifan/Library/Python/3.6/bin
total 40
drwxr-xr-x  7 crifan  staff   224B  4 17 14:35 .
drwx------  4 crifan  staff   128B  4 17 11:06 ..
-rwxr-xr-x  1 crifan  staff   242B  4 17 14:35 pewtwo
-rwxr-xr-x  1 crifan  staff   226B  4 17 14:35 pipenv
-rwxr-xr-x  1 crifan  staff   237B  4 17 14:35 pipenv-resolver
-rwxr-xr-x  1 crifan  staff   232B  4 17 11:06 virtualenv
-rwxr-xr-x  1 crifan  staff   237B  4 17 11:06 virtualenv-clone

➜  robotDemo vi ~/.bashrc
➜  robotDemo cat ~/.bashrc

export NVM_DIR="/Users/crifan/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] &amp;&amp; . "$NVM_DIR/nvm.sh"  # This loads nvm

export PATH="/Users/crifan/Library/Python/3.6/bin:$PATH"

➜  robotDemo source ~/.bashrc
➜  robotDemo echo $PATH
/Users/crifan/Library/Python/3.6/bin:/Users/crifan/.nvm/versions/node/v5.4.1/bin:/Users/crifan/Library/Python/3.6/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
</code>

【总结】

所以此处Mac中本地安装Python3的pipenv的过程就是:

背景是此处之前已经用brew安装过了python3,如果没有,则先去安装:

<code>brew install python3
</code>

然后再去更新python3中的pip:

<code>python3 -m pip install --upgrade --force-reinstall pip
</code>

然后再去,以用户模式安装pipenv:

<code>pip3 install pipenv --user
</code>

注:用户模式的话,不会对全局的python有影响。

然后再去把此处提示的,PATH中缺少的路径:

<code>/Users/crifan/Library/Python/3.6/bin
</code>

加到PATH中去:

先把:

<code>export PATH="/Users/crifan/Library/Python/3.6/bin:$PATH"
</code>

加到.bashrc中 -》为了以后每次启动电脑后,PATH中都包含该路径。

再去:

<code>source ~/.bashrc
</code>

是为了当前此刻,PATH中包含该路径。

这样命令行中就可以找到这些pipenv等工具了。

然后即可切换到你的项目所在的目录,再去:

<code>pipenv install
</code>

即可:

创建对应的虚拟环境所需内容,以及相关的Pipfile和Pipfile.lock

接着,进入对应的虚拟环境:

<code>pipenv shell
</code>

接着就可以做自己要做的事情了,比如安装某个库:

<code>pipenv install flask
</code>

使用完毕后,用:

<code>exit
</code>

或 快捷键:Control+D,即可退出虚拟环境。

转载请注明:在路上 » 【已解决】Mac本地安装Python3的pipenv虚拟环境

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.210 seconds, using 22.22MB memory