[英]Python symlink to python3
So I'm setting up my default variables in a new MacBook M1 and for some reason, my symlink doesn't seem to work.所以我在新的 MacBook M1 中设置我的默认变量,出于某种原因,我的符号链接似乎不起作用。
Why is the following behaviour happening?为什么会发生以下行为? The symlink from
python
to python3
gets lost somehow.从
python
到python3
的符号链接不知何故丢失了。 /Users/overflow/Documents/tools
is part of my PATH
variable. /Users/overflow/Documents/tools
是我的PATH
变量的一部分。
$ type python
python is /Users/overflow/Documents/tools/python
$ python -V
Python 2.7.16
$ ls -lah /Users/overflow/Documents/tools/python
lrwxr-xr-x 1 overflow staff 16B 6 Oct 18:48 /Users/overflow/Documents/tools/python -> /usr/bin/python3
$ /usr/bin/python3 -V
Python 3.8.9
$ echo $PATH | sed 's/:/\n/g'
/Users/overflow/Documents/tools
/Users/overflow/Documents/Dropbox/productivity/bin
/Users/overflow/Documents/tools/confluent-6.1.0/bin
/Users/overflow/.sdkman/candidates/java/current/bin
/Users/overflow/.nvm/versions/node/v16.10.0/bin
/Users/overflow/bin
/usr/local/bin
/opt/homebrew/bin
/opt/homebrew/sbin
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin
Given the path is not being utilized, it is being overridden by a shell alias.鉴于路径未被使用,它被 shell 别名覆盖。 This can be confirmed by typing
set | grep python
这可以通过输入
set | grep python
来确认set | grep python
set | grep python
If you are using virtualenv :如果您使用的是virtualenv :
Try: /usr/bin/python3 -m venv python3.8.9
试试:
/usr/bin/python3 -m venv python3.8.9
The common MacOS python managers are:常见的 MacOS python 管理器有:
List installs using pythonz list
使用
pythonz list
列出安装
Change using: /usr/bin/python3 -m venv python3.8.9
更改使用:
/usr/bin/python3 -m venv python3.8.9
List installs pythonbrew list
列表安装
pythonbrew list
Use pythonbrew switch 3.8.9
to move to the new version.使用
pythonbrew switch 3.8.9
移动到新版本。
Claims to use only $PATH.声称仅使用 $PATH。 Included for completeness, but just in case
包括完整性,但以防万一
List installs pyenv versions
列出安装的
pyenv versions
Use pyenv global 3.8.9
to move to the new version.使用
pyenv global 3.8.9
移动到新版本。
To remove any of these remove the appropriate line from your ~/.bashrc
or ~/.zshrc
file.要删除其中任何一个,请从
~/.bashrc
或~/.zshrc
文件中删除相应的行。
You can locate the line with grep ~/.bashrc python
.您可以使用
grep ~/.bashrc python
找到该行。
I can give you some general troubleshooting tips and a band-aid that can replace a symlink.我可以为您提供一些通用的故障排除技巧和可以替代符号链接的创可贴。
$(which python) -V
This should get you the version for python3.这应该会为您提供 python3 的版本。
Other thing worth checking:其他值得检查的事情:
which python2
This should point to some standard location, /usr/bin/python2
for example.这应该指向一些标准位置,例如
/usr/bin/python2
。 If it isn't pointed there, might be worth understanding why.如果它没有指向那里,可能值得理解为什么。
In general, Macs have some quirks.一般来说,Mac 有一些怪癖。 The fact that a new MacBook M4 ships with Python2 as the default is a smell that you probably shouldn't try to overwrite the default value, and for whatever reason it doesn't seem to want you to.
新的 MacBook M4 附带 Python2 作为默认值的事实是一种气味,您可能不应该尝试覆盖默认值,无论出于何种原因,它似乎都不希望您这样做。
Simple answer: set an alias.简单的答案:设置别名。
echo 'alias python="python3"' >> ~/.zshrc && source;
This will work for you and should not interfere with any potential other systems.这对您有用,并且不会干扰任何潜在的其他系统。
Better answer:更好的答案:
As others have described, create a virtual environment and source venv/bin/activate
.正如其他人所描述的,创建一个虚拟环境和
source venv/bin/activate
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.