pyenv, virtualenv, autoenv can not recognize python - python

I'm using pyenv, virtualenv, autoenv.
When I activated pyenv, it shows an error.
Chois#Chois-MacPro ~ $pyenv activate chacha_dabang
pyenv-virtualenv: prompt changing will be removed from future release. configure `export PYENV_VIRTUALENV_DISABLE_PROMPT=1' to simulate the behavior.
(chacha_dabang) Chois#Chois-MacPro ~ $python
pyenv: python3.5: command not found
The `python3.5' command exists in these Python versions:
3.5.1
So, I checked with which:
(chacha_dabang) Chois#Chois-MacPro ~ $which python
/Users/Chois/.pyenv/shims/python
I execute python with this one :
(chacha_dabang) Chois#Chois-MacPro ~ $/Users/Chois/.pyenv/shims/python
Python 3.5.1 (default, Aug 3 2016, 11:09:57)
[GCC 4.2.1 Compatible Apple LLVM 7.3.0 (clang-703.0.31)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
It works well!!!
I don't know why it doesn't work when I type just python
Need your help.
Here is my PATH :
Chois#Chois-MacPro ~ $echo $PATH
/Usr/local/Cellar/pyenv-virtualenv/20160716/shims:/Users/Chois/.pyenv/shims:/opt/local/bin:/opt/local/sbin:/Library/Frameworks/Python.framework/Versions/3.5/bin:/Users/Chois/Library:/usr/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/git/bin:/Users/Chois/phantomjs-1.9.2-macosx/bin
and .pyenv:
Chois#Chois-MacPro versions $pwd
/Users/Chois/.pyenv/versions
Chois#Chois-MacPro versions $ls
3.5.1 chacha_dabang

Related

Cannot set default python version to 3.10.6 using Pyenv

I'm struggling to update my default python to 3.10.6 on Mac. I seem to be able to set the 'global' and 'local' to the new one (as in code), but this doesn't impact the default...
Help would be much appreciated, please, as I'm a beginner!!
charlieharrison#MacBook-Pro-4 ~ % pyenv global 3.10.6
charlieharrison#MacBook-Pro-4 ~ % pyenv local 3.10.6
charlieharrison#MacBook-Pro-4 ~ % python
WARNING: Python 2.7 is not recommended.
This version is included in macOS for compatibility with legacy software.
Future versions of macOS will not include Python 2.7.
Instead, it is recommended that you transition to using 'python3' from within Terminal.
Python 2.7.16 (default, Mar 25 2021, 03:11:28)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
charlieharrison#MacBook-Pro-4 ~ % pyenv versions
system
* 3.10.6 (set by /Users/charlieharrison/.python-version)
charlieharrison#MacBook-Pro-4 ~ %
Simpliest way is to create a link to latest version, for example:
ln -s -f /usr/local/bin/python3.10 /usr/local/bin/python

why is pyenv still prioritizing the system's python version when I run `python3.x`?

I have pyenv installed and everything works pretty well except for one aspect: when I run the command python3.9, my system still points to my system's version of python (3.9.13). However, I would like to make it point to my pyenv installed version when running python3.9:
❯ pyenv versions
system
3.7.10
3.8.10
* 3.9.5 (set by /Users/username/.python-version)
❯ python3
Python 3.9.5 (default, Jul 7 2022, 20:35:58)
[Clang 13.1.6 (clang-1316.0.21.2.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
❯ python3.9
Python 3.9.13 (main, May 24 2022, 21:13:51)
[Clang 13.1.6 (clang-1316.0.21.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
❯ python3.9 --version
Python 3.9.13
❯ python3 --version
Python 3.9.5
Note that the issue occurs just when running python3.9, not python3.
What's wrong in my configuration?

How to switch AWS CLI to Python 3.7 on macOS?

On macOS Mojave 10.14.6, have the following versions of python installed:
Python 2.7.16
Python 2.7.16 (default, May 17 2019, 18:32:33)
[GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.46.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Python 3
Python 3.7.4 (v3.7.4:e09359112e, Jul 8 2019, 14:54:52)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Installed AWS CLI using these steps:
curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
unzip awscli-bundle.zip
sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
Now, when I test aws from the command line using aws --version
aws-cli/1.16.247 Python/2.7.16 Darwin/18.7.0 botocore/1.12.237
Question(s):
Is this correct?
Is it supposed to be using Python 3.7.4 instead?
If so, how can I switch this over?
By default the installer will use whatever is in your path for python.
If you want to use Python 3, you need to run something like this to run the installer:
sudo /usr/local/bin/python3 awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
Replace /usr/local/bin/python3 with your path for Python 3 if it's different.
All of this said, if you have both Python environments installed, I'm not aware of any reason to prefer one version over the other for the AWS CLI tool.

With Python 2.7.15 on a MAC console, virtualenv creates an environment with a different version of Python

Here is an extract of my console in a Mac, as you can see the Python on the console is 2.7.15 but on the environment it becomes 2.7.10 which is an older version... any help on why and how to fix it would be most welcomed!
dhcp-18-57:Wakeup6 **jbs$ python**
**Python 2.7.15** (default, May 1 2018, 16:44:14)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
dhcp-18-57:Wakeup6 jbs$ virtualenv env
New python executable in /Users/jbs/PycharmProjects/Wakeup6/env/bin/python
Installing setuptools, pip, wheel...done.
dhcp-18-57:Wakeup6 jbs$ source env/bin/activate
(env) dhcp-18-57:Wakeup6 **jbs$ python**
**Python 2.7.10** (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
If you installed python using Anaconda, then set up a new virtual environment for python 2.7.15 Then following directions in the Anaconda documentation, activate this virtual environment and you should be good to go.
If you didn't use Anaconda, just follow the directions for setting up a virtual environment on a Unix box. Then activate that environment and start working.
You can have multiple versions on your computer. Virtual environments allow you to run the version you want. I have virtual environments for python 2.7.13 and python 3.6.
If this doesn't work please let me know. I'll try to help.
Thank you all for your input. I finally figured out how to solve it. The difficult part was finding out how to locate the place where python 2.7.15 was installed which I'll leave intact in the response since I found it by trial and error looking in other places. I have not found a command that gives you the full path (perhaps an expert can tell us how to go from the laconic which python to the full path).
What I find interesting is that it does not really matter what the console uses when calling virtualenv. What matters is the version of Python used to install virtualenv which is the default version that will be used.
Essentially one has to use the -p option in virtualenv and make sure to find the right location where the desired version of python is.
dhcp-18--41:WakeUp8 jbs$ virtualenv -p /usr/local/Cellar/python#2/2.7.15/bin/python env
Running virtualenv with interpreter /usr/local/Cellar/python#2/2.7.15/bin/python
New python executable in /Users/jbs/PycharmProjects/WakeUp8/env/bin/python2.7
Also creating executable in /Users/jbs/PycharmProjects/WakeUp8/env/bin/python
Installing setuptools, pip, wheel...done.
dhcp-18-189-34-41:WakeUp8 jbs$ python
Python 2.7.15 (default, May 1 2018, 16:44:14)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
dhcp-18--41:WakeUp8 jbs$ pwd
/Users/jbs/PycharmProjects/WakeUp8
dhcp-18-189-34-41:WakeUp8 jbs$ source env/bin/activate
(env) dhcp-18-189-34-41:WakeUp8 jbs$ python
Python 2.7.15 (default, May 1 2018, 16:44:14)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

Build Python as UCS-4 via pyenv

I run into this issue ImportError numpy/core/multiarray.so: undefined symbol: PyUnicodeUCS2_AsASCIIString installing Python in a pyenv-virtualenv environment.
In my case, it happens with the matplotlib package instead of numpy (as in the above question), but it's basically the same issue.
The answer given in that question is a simple:
Rebuild NumPy against a Python built as UCS-4.
I don't know how to do this. In this other question it is said that one has to use:
./configure --enable-unicode=ucs4
but I don't know how to use that command along with pyenv.
This issue is also mentioned in pyenv's repo issue list, and a solution given in a comment. Sadly (for me) I can not understand how to apply the fix explained in said comment.
So my question basically is: how do I build Python as UCS-4 via pyenv?
Installing python with pyenv with ucs2:
$ export PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs2
$ pyenv install -v 2.7.11
...
$ pyenv local 2.7.11
$ pyenv versions
system
* 2.7.11 (set by /home/nwani/.python-version)
$ /home/nwani/.pyenv/shims/python
Python 2.7.11 (default, Aug 13 2016, 13:42:13)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_config_vars()['CONFIG_ARGS']
"'--prefix=/home/nwani/.pyenv/versions/2.7.11' '--enable-unicode=ucs2' '--libdir=/home/nwani/.pyenv/versions/2.7.11/lib' 'LDFLAGS=-L/home/nwani/.pyenv/versions/2.7.11/lib ' 'CPPFLAGS=-I/home/nwani/.pyenv/versions/2.7.11/include '"
Installing python with pyenv with ucs4:
$ pyenv uninstall 2.7.11
pyenv: remove /home/nwani/.pyenv/versions/2.7.11? y
$ export PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs4
$ pyenv install -v 2.7.11
...
$ pyenv local 2.7.11
$ pyenv versions
system
* 2.7.11 (set by /home/nwani/.python-version)
$ /home/nwani/.pyenv/shims/python
Python 2.7.11 (default, Aug 13 2016, 13:49:09)
[GCC 4.8.4] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import sysconfig
>>> sysconfig.get_config_vars()['CONFIG_ARGS']
"'--prefix=/home/nwani/.pyenv/versions/2.7.11' '--enable-unicode=ucs4' '--libdir=/home/nwani/.pyenv/versions/2.7.11/lib' 'LDFLAGS=-L/home/nwani/.pyenv/versions/2.7.11/lib ' 'CPPFLAGS=-I/home/nwani/.pyenv/versions/2.7.11/include '"

Categories

Resources