python - 运行 pipenv、mkdocs 时出错:/usr/local/opt/python/bin/python2.7:错误的解释器:没有这样的文件或目录
问题描述
尝试在 Mac 上运行pipenv
&时出现错误:mkdocs
bash:/usr/local/bin/pipenv:/usr/local/opt/python@2/bin/python2.7:错误的解释器:没有这样的文件或目录
$ pipenv
bash: /usr/local/bin/pipenv: /usr/local/opt/python@2/bin/python2.7: bad interpreter: No such file or directory
$ mkdocs
bash: /usr/local/bin/mkdocs: /usr/local/opt/python@2/bin/python2.7: bad interpreter: No such file or directory
$
一些附加信息以防万一有用,命令python
链接到我认为是 Mac 上提供的默认 python 安装:
$ which python
/usr/local/bin/python
$ ls -l $(which python)
lrwxr-xr-x 1 jamiet admin 15 Nov 12 12:58 /usr/local/bin/python -> /usr/bin/python
$ which python3
/usr/local/bin/python3
$ ls -l $(which python3)
lrwxr-xr-x 1 jamiet admin 34 May 2 2019 /usr/local/bin/python3 -> ../Cellar/python/3.7.3/bin/python3
$ python --version
Python 2.7.10
这可能有用也可能没用。
我发现了一个有用的线程,其中有人遇到了类似的问题:pip installation /usr/local/opt/python/bin/python2.7: bad interpreter: No such file or directory我已经遵循了那里的一些建议:
酿造链接--覆盖python
我曾使用 home-brew 在 OS X 10.10 上安装 2.7,但新安装缺少符号链接。我运行了
brew link --overwrite python
,如如何在 Homebrew 中对 python 进行符号链接?它解决了这个问题。
我相信python2最初是使用自制软件安装在这台机器上的,所以我试过了,但没有运气:
$ brew link --overwrite python
Warning: Already linked: /usr/local/Cellar/python/3.7.3
To relink: brew unlink python && brew link python
我还没有(还)尝试过那里的建议(brew unlink python && brew link python
),因为我想尝试其他一些事情并首先从这里获得一些建议
符号链接到正确的位置
pipenv
试图在/期望它的位置创建指向我已知的 python2 解释器的符号链接mkdocs
,但它没有工作:
$ /usr/local/bin/python --version
Python 2.7.10
$ ln -s /usr/local/bin/python /usr/local/opt/python@2/bin/python2.7
ln: failed to create symbolic link '/usr/local/opt/python@2/bin/python2.7': No such file or directory
请注意,如果我尝试稍微不同的命令(即只是不同的路径),那么命令会成功且不会出错:
$ ln -s /usr/local/bin/python /usr/local/opt/python/bin/python2.7
$ ls -l /usr/local/opt/python/bin/python2.7
lrwxr-xr-x 1 jamiet admin 21 Jan 16 16:06 /usr/local/opt/python/bin/python2.7 -> /usr/local/bin/python
但这对我没有帮助,因为pipenv
/mkdocs
期望解释器位于 /usr/local/opt/python@2/bin/python2.7 所以我删除了符号链接
$ rm /usr/local/opt/python/bin/python2.7
任何人都可以提出前进的道路吗?
解决方案
啊,我想我已经设法解决了这个问题:https ://stackoverflow.com/a/54890849/201657建议brew install python@2
。它还需要我安装一些 xcode 工具(xcode-select --install
):
$ brew install python@2
Error: Xcode alone is not sufficient on Mojave.
Install the Command Line Tools:
xcode-select --install
$ xcode-select --install
xcode-select: note: install requested for command line developer tools
$ brew install python@2
Updating Homebrew...
==> Homebrew has enabled anonymous aggregate formulae and cask analytics.
Read the analytics documentation (and how to opt-out) here:
https://docs.brew.sh/Analytics
==> Auto-updated Homebrew!
Updated 4 taps (moul/moul, homebrew/core, homebrew/cask and wagoodman/dive).
==> New Formulae
<snip>
==> Updated Formulae
<snip>
==> Renamed Formulae
<snip>
==> Deleted Formulae
<snip>
==> Installing dependencies for python@2: openssl@1.1, readline and sqlite
==> Installing python@2 dependency: openssl@1.1
==> Downloading https://homebrew.bintray.com/bottles/openssl@1.1-1.1.1d.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/10/104ef018b7bb8fcc49f57e5a60359a28a02d480d85a959e6141394b0571cbb28?__gda__=exp=1579192531~hmac=4e0f24e7c23ef0b179b24e636e0648cf5ddacf1ba593c1eafb99df4abff27dd6&response-content-disposition=attachment%3Bfilename%3D%22openssl%401.1-1.1.1d.mojave.bottle.tar.gz%22&response-content-type=application%2Fgzip&requestInfo=U2FsdGVkX18FOL-sNoEItw923wfVaX0khFxEm_orjuu2BfyA4I5hITIsrm0IlATZztPdR
######################################################################## 100.0%
==> Pouring openssl@1.1-1.1.1d.mojave.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl@1.1/certs
and run
/usr/local/opt/openssl@1.1/bin/c_rehash
openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because openssl/libressl is provided by macOS so don't link an incompatible version.
If you need to have openssl@1.1 first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile
For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
For pkg-config to find openssl@1.1 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
==> Summary
/usr/local/Cellar/openssl@1.1/1.1.1d: 7,983 files, 17.9MB
==> Installing python@2 dependency: readline
==> Downloading https://homebrew.bintray.com/bottles/readline-8.0.1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/3c/3c754391e9d243835811d128771ca0f1a565024100fd2c2871534353d46aaf0e?__gda__=exp=1579192567~hmac=484004e95b8e8bf6a1a3c3b93f2c499fedbc4aabefe7c7e69c441339c3576bc0&response-content-disposition=attachment%3Bfilename%3D%22readline-8.0.1.mojave.bottle.tar.gz%22&response-content-type=application%2Fgzip&requestInfo=U2FsdGVkX1-hB-7PyMBj4HiD3a21IEi6emuN13p6QaZTYdofdpr8PsmH2Wu3ZUE_qPFlc_K8yES
######################################################################## 100.0%
==> Pouring readline-8.0.1.mojave.bottle.tar.gz
==> Caveats
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.
For compilers to find readline you may need to set:
export LDFLAGS="-L/usr/local/opt/readline/lib"
export CPPFLAGS="-I/usr/local/opt/readline/include"
For pkg-config to find readline you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"
==> Summary
/usr/local/Cellar/readline/8.0.1: 48 files, 1.5MB
==> Installing python@2 dependency: sqlite
==> Downloading https://homebrew.bintray.com/bottles/sqlite-3.30.1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/5e/5e6fef2d754e0e4009d502c40ad1846ac46937886b5f3fe89378cb838626d95e?__gda__=exp=1579192572~hmac=a81364a3c7b176d89dceef369d52565faaafb7649a71270cbac0fe60cbc9c96e&response-content-disposition=attachment%3Bfilename%3D%22sqlite-3.30.1.mojave.bottle.tar.gz%22&response-content-type=application%2Fgzip&requestInfo=U2FsdGVkX1-c1S7wGXdJ_YZOPQaAbF12828yGxEYI4O4kHrFKyZT3yZn8p83BUHd5zcz957N2-IJ
######################################################################## 100.0%
==> Pouring sqlite-3.30.1.mojave.bottle.tar.gz
==> Caveats
sqlite is keg-only, which means it was not symlinked into /usr/local,
because macOS provides an older sqlite3.
If you need to have sqlite first in your PATH run:
echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile
For compilers to find sqlite you may need to set:
export LDFLAGS="-L/usr/local/opt/sqlite/lib"
export CPPFLAGS="-I/usr/local/opt/sqlite/include"
For pkg-config to find sqlite you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/sqlite/lib/pkgconfig"
==> Summary
/usr/local/Cellar/sqlite/3.30.1: 11 files, 3.9MB
==> Installing python@2
==> Downloading https://homebrew.bintray.com/bottles/python@2-2.7.17_1.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/54/54d3351d6be8268b2f5017894dcc8e083811dfa3812bdb9f79f989873b9a4542?__gda__=exp=1579192578~hmac=f79ee8bb690769cea6f7025f7266480dad73194bed15f36c005de20cd6cd38af&response-content-disposition=attachment%3Bfilename%3D%22python%402-2.7.17_1.mojave.bottle.tar.gz%22&response-content-type=application%2Fgzip&requestInfo=U2FsdGVkX18s65QivKoSQBP1QqsYGwHQyWAZXRxW-td799ewahemF_jTRodQsHVZ2ko4PZ
######################################################################## 100.0%
==> Pouring python@2-2.7.17_1.mojave.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink bin/python
Target /usr/local/bin/python
already exists. You may want to remove it:
rm '/usr/local/bin/python'
To force the link and overwrite all conflicting files:
brew link --overwrite python@2
To list all files that would be deleted:
brew link --overwrite --dry-run python@2
Possible conflicting files are:
/usr/local/bin/python -> /usr/bin/python
==> /usr/local/Cellar/python@2/2.7.17_1/bin/python -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python@2/2.7.17_1/bin --install-lib=/usr/local/lib/python2.7/site-packages
==> /usr/local/Cellar/python@2/2.7.17_1/bin/python -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python@2/2.7.17_1/bin --install-lib=/usr/local/lib/python2.7/site-packages
==> /usr/local/Cellar/python@2/2.7.17_1/bin/python -s setup.py --no-user-cfg install --force --verbose --single-version-externally-managed --record=installed.txt --install-scripts=/usr/local/Cellar/python@2/2.7.17_1/bin --install-lib=/usr/local/lib/python2.7/site-packages
==> Caveats
Pip and setuptools have been installed. To update them
pip install --upgrade pip setuptools
You can install Python packages with
pip install <package>
They will install into the site-package directory
/usr/local/lib/python2.7/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
==> Summary
/usr/local/Cellar/python@2/2.7.17_1: 3,810 files, 51.3MB
==> Caveats
==> openssl@1.1
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl@1.1/certs
and run
/usr/local/opt/openssl@1.1/bin/c_rehash
openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because openssl/libressl is provided by macOS so don't link an incompatible version.
If you need to have openssl@1.1 first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile
For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"
For pkg-config to find openssl@1.1 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/openssl@1.1/lib/pkgconfig"
==> readline
readline is keg-only, which means it was not symlinked into /usr/local,
because macOS provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.
For compilers to find readline you may need to set:
export LDFLAGS="-L/usr/local/opt/readline/lib"
export CPPFLAGS="-I/usr/local/opt/readline/include"
For pkg-config to find readline you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/readline/lib/pkgconfig"
==> sqlite
sqlite is keg-only, which means it was not symlinked into /usr/local,
because macOS provides an older sqlite3.
If you need to have sqlite first in your PATH run:
echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.bash_profile
For compilers to find sqlite you may need to set:
export LDFLAGS="-L/usr/local/opt/sqlite/lib"
export CPPFLAGS="-I/usr/local/opt/sqlite/include"
For pkg-config to find sqlite you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/sqlite/lib/pkgconfig"
==> python@2
Pip and setuptools have been installed. To update them
pip install --upgrade pip setuptools
You can install Python packages with
pip install <package>
They will install into the site-package directory
/usr/local/lib/python2.7/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
现在...
$ /usr/local/opt/python@2/bin/python2.7
Python 2.7.17 (default, Dec 23 2019, 21:25:34)
[GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.33.16)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
$ ls -l /usr/local/opt/python@2/bin/python2.7
lrwxr-xr-x 1 jamiet DHDOM1\Domain Users 57 Oct 19 19:58 /usr/local/opt/python@2/bin/python2.7 -> ../Frameworks/Python.framework/Versions/2.7/bin/python2.7
$ pipenv
Usage: pipenv [OPTIONS] COMMAND [ARGS]...
$ mkdocs
Usage: mkdocs [OPTIONS] COMMAND [ARGS]...
耶!
推荐阅读
- python - 将数据帧数据附加到 json 文件而不删除以前的内容
- uwp - 如何从内容对话框中删除填充?
- google-chrome - 移动仿真 >> 元素不可点击 - 将 chrome 浏览器和 chrome 驱动程序更新到最新版本后
- php - Laravel Cashier cancel() 抛出 BadMethodCallException
- java - @OneToMany @JoinTable 使用三个表
- sonarqube - SonarQube 与 Teamcity 的集成。分析 Go 项目时出错
- python - Python 文件在 Python IDLE 中正常运行但在线给出错误
- unity3d - Don'tDestroyOnLoad 在场景 Unity 之间不起作用
- c++ - 具有“包含”和“在”关系的循环依赖
- cygwin - Cygwin 的 tr 命令,“tr -s [:blank:] ' '”,替换文本文件中小写 'a' 的实例