I installed Python 3 using the Cygwin terminal. There were no issues during installation.
I get this:
$ which python3
/usr/bin/python3
and
$ whereis python3
python3: /usr/bin/python3 /usr/bin/python3.6 /usr/lib/python3.6 /usr/lib/python3.8
/usr/include/python3.6m /usr/include/python3.8 /usr/share/man/man1/python3.1.gz
But neither of
$ python3 $ python3 main.py $ python3 --version
give any output. I have done this the same way before on the same computer and it worked fine. What did I do wrong this time? Or forgot to do?
Try to create an alias to attach python to the common name "python3". In your Cygwin terminal write:
$ alias python3=$(which python3.6)
python3 should be a link managed by alternatives pointing to python3.8
$ alternatives --display python3
python3 - status is auto.
link currently points to /usr/bin/python3.8
/usr/bin/python3.6 - priority 36
/usr/bin/python3.7 - priority 37
/usr/bin/python3.8 - priority 38
Current `best' version is /usr/bin/python3.8.
that belongs to python38 package
$ cygcheck -f /usr/bin/python3.8
python38-3.8.7-3
verify that python38 is correctly installed
$ cygcheck -c python38
Cygwin Package Information
Package Version Status
python38 3.8.7-3 OK
and that there are no issue on the dependency
$ cygcheck /usr/bin/python3.8.exe
D:\cygwin64\bin\python3.8.exe
D:\cygwin64\bin\cygwin1.dll
C:\WINDOWS\system32\KERNEL32.dll
C:\WINDOWS\system32\ntdll.dll
C:\WINDOWS\system32\KERNELBASE.dll
D:\cygwin64\bin\libpython3.8.dll
D:\cygwin64\bin\cygintl-8.dll
D:\cygwin64\bin\cygiconv-2.dll
D:\cygwin64\bin\cyggcc_s-seh-1.dll
More likely you need to re-install python38 or one of the needed libraries
$ cygcheck -f /usr/bin/cygwin1.dll /usr/bin/cygintl-8.dll /usr/bin/cygiconv-2.dll /usr/bin/cyggcc_s-seh-1.dll
cygwin-3.1.7-1
libgcc1-10.2.0-1
libiconv2-1.16-2
libintl8-0.19.8.1-2
be sure to stop all Cygwin processes before re-installing the packages; specially any running service
Related
I am currently running python 3.6 on my Mac, and installed the latest version of Python (3.11) by downloading and installing through the official python releases. Running python3.11 opens the interpreter in 3.11, and python3.11 --version returns Python 3.11.0, but python -V in terminal returns Python 3.6.1 :: Continuum Analytics, Inc..
I tried to install again via homebrew using brew install python#3.11 but got the same results.
More frustrating, when I try to open a virtual environment using python3 -m venv env I get
Error: Command '['/Users/User/env/bin/python3', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 1.
I altered .bash_profile with
# Setting PATH for Python 3.11
# The original version is saved in .bash_profile.pysave
PATH="/Library/Frameworks/Python.framework/Versions/3.11/bin:${PATH}"
export PATH
. "$HOME/.cargo/env"
And created a .zprofile based on this post with
export PYTHONPATH=$HOME/Users/User
and a .zshrc based on this post, but --version still throws python3.6.
I'm running Big Sur OS. Pip and homebrew are up to date and upgraded. Acknowledging that I'm totally foolish, what do I need to do to get python >3.7 running in terminal?
What you want to do is overwrite a python symlink.
After installing python via homebrew, you can see that python3.11 is just symlink.
cd /usr/local/bin; ls -l | grep python3.11
The result is:
lrwxr-xr-x 1 user admin 43 Nov 7 15:43 python3.11# -> ../Cellar/python#3.11/3.11.0/bin/python3.11
So let's just overwrite it.
ln -s -f $(which python3.11) $(which python)
ln -s -f $(which python3.11) $(which python3)
ln -s -f $(which pip3.11) $(which pip)
ln -s -f $(which pip3.11) $(which pip3)
After these commands, pip, pip3, python3, python will invoke the version 3.11.
This command makes soft symlink.
ln -s
This command with -f option overwrite an existing soft symlink.
A soft symlink is similar to a shortcut.
In man page,which command is described as
which - shows the full path of (shell) commands.
I have Python3.6 and Python3.8 installed on Ubuntu 18.04. When I execute python3 -V I get python3.8.0, which is correct. That's currently my default Python.
I used the Ubuntu 18.04 package repository when I installed Python3.6 and Python3.8. I just built Python3.10 from source and I want to set that as the default now. The canonical way to change is with --update-alternatives, but I did not do that when I installed Python3.6 and Python3.8, so when I execute:
update-alternatives --query python
update-alternatives: error: no alternatives for python
Python3.8 is in /usr/bin/python3.8 and Python3.10 is in /usr/local/bin/python3.10.
According to what I have read on the net, I should do this:
$ sudo update-alternatives --install /usr/local/bin/python python /usr/bin/python3.8
$ sudo update-alternatives --install /usr/local/bin/python python /usr/local/bin/python3.10
Then I select the default with sudo update-alternatives --config python.
Because I currently don't have any alternatives but I was somehow able to switch from Python3.6 to Python3.8 (I don't remember how), will the commands above cause any problems? Is there a problem in the different locations for 3.8 (/usr/bin/) vs 3.10 (/usr/local/bin/) and what will be the effect of the symlink for 3.10 going into /usr/local/bin/ where it's already located.
Naturally I could just try it, but if there is an issue I'm not sure how to back out of it if it goes wrong. I've gotten a lot of differing information on the net.
Thanks for any help.
I have answered my own question. First, I did have alternatives, but as Ubuntu defaults to Python2 (please Ubuntu change that -- the world has moved on), the command is sudo update-alternatives --config python3:
$ sudo update-alternatives --config python3
There are 2 choices for the alternative python3 (providing /usr/bin/python3).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.8 2 auto mode
1 /usr/bin/python3.6 1 manual mode
2 /usr/bin/python3.8 2 manual mode
Note the line "providing /usr/bin/python3." That means the Python symlinks for Python 3 are in /usr/bin/python3. So I add the new one:
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.10 3
That makes Python 3.10 priority 3, the highest priority. Then:
$ python3 --version
Python 3.10.0
I hope that helps someone in the future.
I have multiple Python versions, and thus also include multiple Python binary executables.
ls /usr/bin/python*
shows the python environments in my ubuntu 18.04
/usr/bin/python /usr/bin/python2.7 /usr/bin/python2-pbr /usr/bin/python3 /usr/bin/python3.5m /usr/bin/python3.6-config /usr/bin/python3.6m-config /usr/bin/python3m
/usr/bin/python2 /usr/bin/python2-jsonschema /usr/bin/python2-wsdump /usr/bin/python3.5 /usr/bin/python3.6 /usr/bin/python3.6m /usr/bin/python3-config /usr/bin/python3m-config
in order to satisfy the PyFlink requirement regarding the Python environment version, i have to choose to soft link python to point to your python3 interpreter:
ln -s /usr/bin/python3 python
however when I use the command, it tells me
ln: failed to create symbolic link 'python': File exists
so i wonder do I need to delete the /usr/bin/python first and then use the command to create the soft link?
Command ln -s /usr/bin/python3 python creates link ./python pointing to /usr/bin/python3. You probably executed it multiple times so ./python already exists. You could overwrite it by providing -f flag to ln.
You definitely should not delete /usr/bin/python.
The whole idea with manually creating links to Python interpreter to install a package seems very weird. I suggest one of the following options:
just use the full path to the interpreter: /usr/bin/python3.6 -m pip install <package>; if the package adds any scripts globally usable from command line, like pyspark, they will be installed with hashbang pointing to the interpreter you installed them with
use a virtual environment: /usr/bin/python3.6 -m venv ~/.env-py36; source ~/.env-py36/bin/activate; python -m pip install <package>
use something like pyenv
I setup Python 3.6 using pyenv so I could manage multiple Python versions (e.g. 3.7 and 3.8) in the future. I didn't use Homebrew to install Python since it changes the system version. It's my first time to use zsh shell since it's the default shell in Catalina OS. Currently, I use 3.6.8 version for my existing project.
So here's my current setup:
% pyenv versions
result:
system
* 3.6.8 (set by /Users/macbook/.python-version)
3.7.3
% python -V results to Python 3.6.8
% which python results to /Users/macbook/.pyenv/shims/python
% echo $PATH results to /Users/macbook/.pyenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
The content of my ~/.zshrc is PATH=$(pyenv root)/shims:$PATH
I created a virtual env using % python -m venv venv, installed all the necessary packages, and when I activate it and get the python path,
(venv) % python -V
Python 3.6.8
(venv) % which python
/Users/macbook/python-project/venv/bin/python
(venv) % echo $PATH
/Users/macbook/python-project/venv/bin:/Users/macbook/.pyenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
Finally, when I try to run the app, I always get zsh: abort error:
(venv) % python app.py
zsh: abort python app.py
(venv) % export FLASK_APP=app.py
(venv) % flask run
zsh: abort flask run
I don't know what else is still missing or are there anything wrong with my python path?
Thanks!
After searching through the web, I think this is a common issue with the latest MacOS or Homebrew. This thread fixed the issue.
brew update && brew upgrade && brew install openssl
copy the two files from /usr/local/Cellar/openssl#1.1/1.1.1g to /usr/local/lib/
cd /usr/local/Cellar/openssl#1.1/1.1.1g/
sudo cp libssl.1.1.1.dylib libcrypto.1.1.1.dylib /usr/local/lib/
add symlink to missing openssl libs
cd /usr/local/lib
sudo ln -s libssl.1.1.1.dylib libssl.dylib
sudo ln -s libcrypto.1.1.1.dylib libcrypto.dylib
For me, the below worked:
Python 3.6.9
MacOs Catalina 10.15.7
cd /usr/local/Cellar/openssl#1.1/1.1.1h/
cp lib/libssl.1.1.dylib lib/libcrypto.1.1.dylib /usr/local/lib
cd /usr/local/lib
sudo ln -s libssl.1.1.dylib libssl.dylib
sudo ln -s libcrypto.1.1.dylib libcrypto.dylib
Thanks to the answer by Zhanrah
Currently when I use "python" command, it points to python2.6. I have installed python3.1 and I want the "python" command point to python3.1. How it is possible?
mahmood#mpc:~$ which python
/usr/bin/python
mahmood#mpc:~$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 2010-11-24 16:14 /usr/bin/python -> python2.6
mahmood#mpc:~$ uname -a
Linux orca 2.6.32-24-server #39-Ubuntu SMP Wed Jul 28 06:21:40 UTC 2010 x86_64 GNU/Linux
Since you have Linux, and if you want to simply type "python" instead of "python3" in order to run Python programs, a solution is simply to define an alias in you shell configuration file (.bashrc, etc.). For Bourne shells, it should be something like
alias python=python3
(or whatever your Python 3 name is).
This way, you do not have to change anything on your system, so this solution should quite innocuous and it should not break your system.
You really don't want to change what python points to, because some programs might expect Python 2, and break.
The solution is to use virtualenv: create an isolated Python 3 environment (with the -p python3 option), activate it, and you're good to go.
unlink /usr/bin/python
ln -s /usr/bin/python3.1 /usr/bin/python
It is not advisable.
You could write at the top in your own script (a shebang):
#!/usr/bin/env python3
If you're on Windows then install pylauncher. It understands #!.
On Linux to make your script executable, run once:
$ chmod +x your-script
After that, to run your script:
$ ./your-script
For interactive use you could create virtualenv as #Petr Viktorin points out. To install/upgrade (versions from Ubuntu's repositries are too old):
$ pip install -U virtualenv{,wrapper}
Follow instructions in /path/to/virtualenvwrapper.sh, to create virtualenv that uses python3:
$ mkvirtualenv --python python3 py3
To activate virtualenv:
$ workon py3
In an active virtualenv python refers to /path/virtualenv/bin/python. So you could run:
$ python your_module.py
You could follow this procedure:
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3.1 /usr/bin/python
But as already stated by Petr Viktorin, any programs that would expect python v2 would stop to work. So use with caution. You can undo the change by running:
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python2.6 /usr/bin/python
On Linux/Mac OS you can use python3 instead of python.