- pyenv local/global не работает на каталине
- 4 ответа
- pyenv local/global not working on catalina
- 5 Answers 5
- pyenv local — can’t set a Python version by its number despite the fact that it’s installed
- 3 Answers 3
- pyenv don’t switch between python versions on macos #1446
- Comments
- gsscoder commented Nov 2, 2019 •
- asmaier commented Nov 6, 2019 •
- gsscoder commented Nov 6, 2019
- asmaier commented Nov 6, 2019
- gsscoder commented Nov 7, 2019
- cseder commented Nov 9, 2019 •
- Cannot switch Python with pyenv
- 16 Answers 16
- Background
- Solution
pyenv local/global не работает на каталине
У меня новый MacBook со свежими установками всего, что я обновил до macOS Catalina. Я установил homebrew, а затем pyenv и установил Python 3.8.0 с помощью pyenv. Казалось, что все это работает должным образом.
Однако ни pyenv local ни pyenv global похоже, вступают в силу. Вот все подробности того, что я вижу:
Кстати, нет /bin в моем.pyenv я добавил эти команды только в соответствии с некоторыми другими инструкциями, но я планирую удалить их, потому что считаю, что это неправильно:
Стоит отметить, что Каталина перешла на zsh из bash, не уверена, что это актуально здесь.
4 ответа
Я добавил следующее в свой
/.zprofile и заставил его работать.
Если вы используете pyenv с pipenv и столкнувшись с той же проблемой, вы можете добавить следующие строки в свой .zshrc или .zprofile файл:
Ссылка pyenv с /shims папка помогает сделать его более общим и позволяет легко переключаться между различными версиями Python, если у вас установлено несколько версий.
pipenv тогда всегда будет ссылаться на версию Python, которая в настоящее время установлена как глобальная pyenv .
Проверьте, существуют ли какие-либо символические ссылки в корне вашей учетной записи
если у вас нет файлов символических ссылок
и попробуйте снова установить python с помощью pyenv
Catalina (и OS X в целом) использует /etc/zprofile установить $PATH перед тем, что вы указываете в локальных точечных файлах.
он использует path_helper утилита для указания $PATH и я подозреваю, что это отменяет инъекцию прокладки в ваших локальных точечных файлах. я обнаружил, что самый простой способ добиться моего предпочтительного поведения — это закомментировать следующие строки в /etc/zprofile .
есть опция, которую я хотел изучить, чтобы использовать неустановленную $GLOBAL_RCS как указано в man zhsoptions , но в глобальных файлах RC есть и другие полезные вещи, так что это похоже на слишком большой молоток. /etc/zprofile влияет только на интерактивные оболочки, поэтому комментируя эти строки и выполняя явные $PATH управление в моих локальных точечных файлах кажется наименее инвазивным средством решения этой проблемы.
Источник
pyenv local/global not working on catalina
I have a new MacBook with fresh installs of everything which I upgraded to macOS Catalina. I installed homebrew and then pyenv, and installed Python 3.8.0 using pyenv. All these things seemed to work properly.
However, neither pyenv local nor pyenv global seem to take effect. Here are all the details of what I’m seeing:
BTW there is no /bin in my .pyenv, I only added those commands per some other instructions but I’m planning to remove it because I think it is wrong:
It’s worth noting that Catalina moved to zsh from bash, not sure if that’s relevant here.
/.pyenv/versions/3.8.0/ As for .zshrc that file doesn’t exist. I don’t have other zsh files in my home directory, and in fact .zshenv is a file I made myself.
5 Answers 5
If you’re using pyenv with pipenv and encountering the same issue, you can add the following lines to your .zshrc or .zprofile file:
Referencing pyenv ‘s /shims folder helps to keep it more general and to allow you to easily switch between different Python versions, should you have more than one installed.
pipenv will then always reference the version of Python that is currently set as global by pyenv .
I added the following to my
/.zprofile and got it working.
Check if exist any symbolic links on your account root
if you don’t have symlink files
and try python install again with pyenv
I think the issue is due to the default HD partitions that might be causing confusion. «With macOS Catalina, you can no longer store files or data in the read-only system volume, nor can you write to the «root» directory ( / ) from the command line, such as with Terminal» (https://support.apple.com/en-ca/HT210650). I had the same issues on macbook pro and imac, which forced me to perform factory resets. I’ve given up on pyenv and decided to go with Anaconda to manage python versions.
catalina (and OS X in general) uses /etc/zprofile to set the $PATH in advance of what you’re specifying within the local dotfiles.
it uses the path_helper utility to specify the $PATH and i suspect this is overriding the shim injection in your local dotfiles. you can comment out the following lines in /etc/zprofile . this will get overridden in subsequent OS updates.
alternately, and less intrusively, you can unset the GLOBAL_RCS option (add unsetopt GLOBAL_RCS ) in your personal .zshenv file which will allow you to suppress sourcing all of the system default RC files for zsh and allow the pyenv shims to operate as intended.
Источник
pyenv local — can’t set a Python version by its number despite the fact that it’s installed
Any suggestions on how you set the version of Python for pyenv?
3 Answers 3
You need to set up an virtual env first. For example, you can create a env called pyenv360 by
And set it as your default python for your folder my-folder by
By doing this, whenever you enter this folder, it’ll start using pyenv360 which references python 3.6.0 in this case.
You can check if it’s working by:
which should show pyenv360 .
(Assuming you installed pyenv according to the official instructions.)
pyenv recognizes two kinds of Python installations:
- system — Python executables from PATH , regardless of their versions
- numbered versions — installed with pyenv install under $PYENV_ROOT/versions
pyenv considers the former installations outside its control, so its commands don’t take their versions into account when looking for a specific version.
To find out which installation, from pyenv ‘s POV, your python3 refers to, check
- pyenv versions
- whether the selected Python 3 version is «system»; or
- which python3 (and pyenv which python3 if the former points into
/shims/ )
- whether the result points to outside $PYENV_ROOT
If your 3.6.0 installation is indeed outside of pyenv ‘s control, you need to select it with pyenv local system and make sure on your own that your PATH is arranged to point to it.
- More specifically, that your PATH first points to
/shims and then to the correct python3
- You can use which -a python3 to quickly check that
Overview
‘pyenv’ has the feature to set the ‘local’ and the ‘global’ version,
where ‘local’ is the version that we set for a particular directory and it automatically gets activated if you are in that directory or any of its subdirectory(if another ‘local’ is not set for that subdirectory) in a hierarchical fashion.
whereas ‘global’ is the version that we set for all over the system and it is available to any directory(if the local is not set for that directory otherwise the local version would be available in that directory)
How to set ‘global’ and ‘local’
now to set ‘global’ or the ‘local’ version of the python, that python version should be installed in your system, be it by the ‘os’ you used or by the ‘pyenv’. And there is no need of virtual environment creation at all.
To Install any version via ‘pyenv’
see the output of pyenv install —list choose one of the name(eg. 3.6.0) and use command pyenv install
Note that the version of python that is installed by the os is called ‘system’ by the ‘pyenv’ and the versions that are installed by the ‘pyenv’ would be represented by the version number of that python version. to see all the versions installed by the pyenv use pyenv versions
Now coming to the question of how to set the global version and the local version, use
pyenv global (the version has to be installed) to set the global version
and for setting the local python, first, move to the directory in which you want to set the local version, and then
Issue that I faced in ubuntu 20.04, and in Linux mint 20
Now sometimes the ‘system’ python is not accessible due to its unreachability by ‘pyenv’ and the reason is well explained by @ivan_pozdeev, but I would like to address the wired issue that I face in ubuntu 20.04 and Linux mint 20(as it’s based on ubuntu 20.04).
Here I am not able to access the system python, even though the system python binaries are well in the path of pyenv.
the error was pyenv: system version not found in PATH
reason: the ‘system’ is not found by the pyenv, because pyenv was looking for binaries with name ‘python’ and not ‘python3’ in the path(which is ‘/usr/bin’), and in ubuntu 20.04 the python binaries are addressed with name ‘python3’, and not with ‘python’
solution: the solution is to create the symlink for ‘python3’ named as ‘python’ in ‘/usr/bin’ and the command used is sudo ln -s /usr/bin/python3 /usr/bin/python
Источник
pyenv don’t switch between python versions on macos #1446
Comments
gsscoder commented Nov 2, 2019 •
I was enable to find an issue on that, but if already exists plese let me know.
- Platform: macOS Catalina 10.15
- pyenv version: 1.2.14 (from brew )
- Python version: 2.7.16 (pre-installed in system)
- C Compiler information: clang-1100.0.33.8
- Python 3.8.0 build/install with Pyenv and debug switched on: https://gist.github.com/gsscoder/dcb61529b94c6f6b9e552dda22e1d9e1
I’ve also created a .zshrc file like stated in pyenv documentation (since I run zsh on iTerm). Restarted the shell and tried also pyenv rehash .
But also if 3.8.0 is set instead of system, python -V still shows system version.
The text was updated successfully, but these errors were encountered:
asmaier commented Nov 6, 2019 •
I have the same problem on macOS 10.14.6 (system: Python 2.7.10) with pyenv 1.2.13 and Python 3.7.4 (installed via homebrew).
But I figured out, that you can make it work if you add
at the end of your .zshrc or .bash_profile .
But make sure to check what is your default shell with, e.g.
so you add the line to the correct file.
gsscoder commented Nov 6, 2019
Thanks for suggestion. Anyway I’ve already tried it first times and didn’t worked.
I’ve put this first in .bash_profile than .zshenv , but pyenv was still unable to switch between python versions.
I think that maybe something about shell configuration (in my case zsh ), but for now I can’t figure out what it is.
asmaier commented Nov 6, 2019
Try to add it to the end of the .bash_profile or .zshrc .
gsscoder commented Nov 7, 2019
Already tried! Didn’t solve.
cseder commented Nov 9, 2019 •
First of all, why do you even have a .bash_profile on Catalina? Have you installed Bash via brew or something after installing, or have you upgraded to Catalina from Mojave or earlier?
Catalina doesn’t ship with Bash, it uses Zsh as the default shell. If you have this left over from an upgrade, copy the things you need into
/.zprofile and delete the bash scripts unless you’re actually using Bash.
Also, you should not update your PATH in .zshrc, this file is read by all processes that uses Zsh, both login shells and interactive shells. Basically every new tab you open in your terminal will execute .zshrc so it should be kept as clean as possible, used only for setting up shell and session specific stuff, not user-wide or system-wide variables.
Aliases is fine to have in .zshrc, not exports.
Use .zprofile for setting up your PATH and other exports that is supposed to last for a user session, e.g until you log out or shut down your Mac. It is used by the login shell, but not interactive shells and other processes.
Depending on what you have installed and how it is installed you might have stuff in your shell initialization files that alters the PATH and inserts directories in front of the path, like the shims for rbenv and pyenv does. It’s important to know what goes where and when.
The order in which Zsh reads your shell files on login and when firing up a Terminal is:
Not all these are required, but if they exist this is the order in which they’re executed.
Also, Apple are forcing the standard directories to be injected first in your path if you have
/.zshenv existing by silently calling /usr/libexec/path_helper which puts you back to square one so to speak if you’re trying to manage what goes where in your PATH.
I solve this in the following way on macOS, because it has this method of action:
/.zshenv (delete it)
Don’t use
/.zlogin (delete it)
DO USE
/.zprofile for setting things like PATH and other exports
DO USE
/.zshrc for setting Zsh specific options and aliases
This way you only need to concern yourself with TWO files. One for setting Zsh specific stuff and one for everything else.
If you do it like this, you can put the following into your .zshrc, to force the order YOU want the entries to have:
If you do it this way, you’re always in control of your PATH.
BTW! When you want to reload these files in an open terminal, just run:
zsh -l
(that’s a lower-case L)
to trigger the re-read of the login initialization files, or just close and open a new Terminal.
Источник
Cannot switch Python with pyenv
I would like to use pyenv to switch python2 and python3.
I successfully downloaded python2 and python3 and pyenv with following codes.
However, I cannot switch from python2 to python3..
I do not understand why this happens.
For your information. My python is in this directory.
Thank you in advance.
16 Answers 16
Try this: eval «$(pyenv init -)»
[July 2021]
If you see this message when running eval «$(pyenv init -)»
you should check the message from pyenv init as the warning says, but in a nutshell, you can use eval «$(pyenv init —path)» instead.
And don’t forget to accordingly update your
/.zshrc or the like if necessary.
You forgot to add this eval «$(pyenv init -)» .
Add this to your .bash_profile or .bashrc file (mac
For me, this worked on MacOS with ZSH after installing via Homebrew:
I initially had eval «$(pyenv init -)» inside of my
/.zshrc file, but that didn’t seem to work. After following this guide: https://github.com/pyenv/pyenv#basic-github-checkout I remved the eval call from the .zshrc file and added it to the .zprofile file using the above command and after restarting terminal everything worked.
/.zprofile file and
/.zshrc didn’t mention pyenv at all so I just ran echo ‘eval «$(pyenv init —path)»‘ >>
/.zshrc and it worked.
/.zshrc could be the root cause.
This is a great opportunity to learn about how pyenv works under the hood.
The pyenv global command simply reads the data in your /Users/Soma/.pyenv/version directory. It’s basically the same as cat /Users/Soma/.pyenv/version .
The pyenv versions command is just checking through the hierarchy and selecting the right Python version to use when a «shim interceptable» command like python or pip is run.
When you run pyenv global 3.5.0 , the /Users/Soma/.pyenv/version file is updated to contain «3.5.0». That’s the only change pyenv makes. Most users are surprised that pyenv global 3.5.0 only changes a single line in a text file!
When you run python —version , your Terminal will perform the same steps it performs when any shell command is executed: it goes through each directory in your PATH and looks for the first executable named python .
If you type echo $PATH , you’ll have something like this: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Your machine is finding the python executable in the /usr/bin directory.
You can add this code to your
/.bash_profile file to change your PATH.
Restart your terminal, run echo $PATH again, and you’ll now see output like this: /Users/Soma/.pyenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Notice how the /Users/Soma/.pyenv/shims directory is at the start of the PATH now. When you run python —version now, the command will be handled by the python executable in /Users/Soma/.pyenv/shims . The command won’t have an opportunity to be picked up by /usr/bin/python because it’ll be grabbed by /Users/Soma/.pyenv/shims/python first.
I can see why this bug confuses you. It’s hard to debug this unless you know how pyenv works.
/ .bashrc file needs to be updated and change eval «$(pyenv init -)» to eval «$(pyenv init —path)»
Just FYI, if your executable has been found EARLIER than the pyenv’s shim location then you will not be able to change python version when you type python in your shell.
To use pyenv properly, shim directory should be the very first thing in your PATH variable. For example,
if your PATH looks like
And if you have a python executable in /usr/bin , you will not be able to use pyenv properly. You should arrange your PATH configuration in
/.bashrc like below
Then restart your shell and you’ll be fine. For me, I had these lines in my
As you can see, I had export PATH=/usr/bin:$PATH after pyenv configuration lines. Then I solved the issue by switching the blocks like below
Run pyenv init and do exactly what it tells you to do.
For me, the solution was adding the following to .profile :
And also adding this line to .bashrc :
Don’t forget to restart your shell. (Close and reopen or exec «$SHELL» )
Check your PATH . Somehow I have .pyenv/bin , when it should be .pyenv/shims .
Fix the path with export PATH=»$HOME/.pyenv/shims:$PATH» (and add to zshrc etc).
Background
- now: 20210926
- Mac: 10.15.7
- pyenv: 2.0.7
Solution
for current console
for work after every boot
if you want auto take effect after Mac boot, then add it to you boot script
here my is zsh, so:
eval «$(pyenv init —path)»
This answer is only for people that are using Fish shell and find this thread. Pyenv uses shims, ref, so in order to make pyenv work with your fish shell you have to edit your
/.config/fish/config.fish file an append the pyen shim directory at the beginning of your $PATH variable. Here is what my config.fish looks like.
The relevant lines here are
The first creates a variable for the pyenv shim path, the second adds it to the front of your path variable. Just save&close, restarted your terminal session and you should be all set.
After installing the correct version, close all terminals and try pyenv global 3.7.2 then try python —version, it should work
Double check if you’ve set path before manually. In my case I added alias to old python in my .zshrc file and after removing it worked fine!
There are situation where one cannot update
/.bash_profile because the machine is shared. In that case adding eval «$(pyenv init —path)» to the bash script should still work, because pyenv init adds the path to pyenv shims to the $PATH. e.g., pyenv will execute a command like this:
Hope this explains why it is working. Alternatively, one should be able to just export the /path/to/.pyenv/shims in their bash script and it should enable pyenv to switch python versions.
I was also facing a situation where eval «$(pyenv init -)» indeed helped switch python version to 3.8.8. But when I started a virtual environment, the python version inside the virtual environment creation would fail:
But with eval «$(pyenv init —path)» the virtual environment also got the 3.8.8. version of python .
I ran into the same problem and ended up making some changes to the way pyenv init goes about setting up the shell but in the end it works the same. The only real difference from the guide on the pyenv github page is that I had to add the $(pyenv root)/bin directory to my path too.
The reason I did this was to avoid long shell startup times from running eval «$(pyenv init -)» and all the other .bash_profile work that goes into my local shell environment. Just to be clear; Pyenv itself doesn’t create a bad shell experience, in my humble opinion, but when you work with several languages that all have their own version management systems and tools that like to be initialized from the .profile with pyenv , etc., the shell initialization process can get slow.
Here’s the steps I took to set myself up, at a high view:
- Run the dry-run version of the pyenv init command so you can see what it would have done for you.
- Put the PATH and shell environment vars into your .bash_profile (or whatever file your distro uses).
- Put the function pyenv init printed into your .bashrc and source your .bashrc from your .bash_profile
This is one way to get it done but it’s better to use this as «pseudo-code». You should exchange .bash_profile for whatever file your distro prefers.
The next bit updates your shell with a new bit of logic that we copied from the pyenv init dry run from step 1, above.
Источник