I have python 3.10 installed. But I am trying to use a python script which is only compatible with python 3.9.
So I have installed 3.9.
wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tar.xz
tar -xf Python-3.9.0.tar.xz
cd Python-3.9.0
./configure
sudo make altinstall
Python 3.9 is now installed, so I have bother 3.9 and 3.10 installed.
When I search how to use 3.9 most results say to delete 3.10.
Is there an option to temprarily switch to 3.9? So after can switch back to 3.10?
Thanks
When you have:
$ ls -l /usr/bin/python3.10
-rwxr-xr-x 1 root root 5921160 Nov 14 17:10 /usr/bin/python3.10
$ ls -l /usr/local/bin/python3.9
-rwxr-xr-x 1 root root 15651728 Dec 31 15:58 /usr/local/bin/python3.9
Then you can do:
sudo update-alternatives --install /usr/bin/python3 python /usr/local/bin/python3.10 0
sudo update-alternatives --install /usr/bin/python3 python /usr/local/bin/python3.9 0
After this being done, this should work:
$ python3
Python 3.10.6 (main, Nov 14 2022, 16:10:14) [GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python3).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.10 0 auto mode
1 /usr/bin/python3.10 0 manual mode
2 /usr/local/bin/python3.9 0 manual mode
Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/local/bin/python3.9 to provide /usr/bin/python3 (python) in manual mode
$ python3
Python 3.9.0 (default, Dec 31 2022, 15:24:44)
[GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
$
After the update-alternatives process, you should find this link:
$ ls -l /usr/bin/python3
lrwxrwxrwx 1 root root 24 Dec 31 16:17 /usr/bin/python3 -> /etc/alternatives/python
and in '/etc/alternatives' a link, named python which points to:
python -> /usr/local/bin/python3.9
or
python -> /usr/bin/python3.10
NOTE: You need to do the same for pip (or pip3), and other tools that relate to python3
Related
I'm unsure about some small obscure details that I worry will have large effects. On my Raspbian Debian 11 running on a Raspberry Pi, sudo apt update && sudo apt full-upgrade only updates my libxml2 library to version 2.9.10, no further. However, I need version 2.9.14 for the security patches contained within. With help from this question (thank you Esther!), I decided to compile version 2.9.14 from source. Everything went well, and the library was placed into /usr/local/lib. I then updated ldconfig by following this answer. However, although that should have made Debian use the new 2.9.14 version, apt-cache policy libxml2 still shows:
libxml2:
Installed: 2.9.10+dfsg-6.7+deb11u2
Candidate: 2.9.10+dfsg-6.7+deb11u2
Version table:
*** 2.9.10+dfsg-6.7+deb11u2 500
500 http://raspbian.raspberrypi.org/raspbian stable/main armhf Packages
100 /var/lib/dpkg/status
I think I know why this is. If I was installing a never-before-seen library, everything might have worked properly. However, since I now have a second libxml2 library without removing the 1st, any time the system needs to use libxml2, the search first reaches /usr/lib/arm-linux-gnueabihf where the old libxml2 is, so the system finds the old version, is satisfied, and so stops searching before finding the new version.
For context before I continue:
(link to below but in color: https://i.stack.imgur.com/OJLJW.png)
pi#fuelightcontrol:~ $ cd /usr/lib/arm-linux-gnueabihf/
pi#fuelightcontrol:/usr/lib/arm-linux-gnueabihf $ ls -l | grep libxml2
lrwxrwxrwx 1 root root 17 May 15 14:58 libxml2.so.2 -> libxml2.so.2.9.10
-rw-r--r-- 1 root root 1510312 May 15 14:58 libxml2.so.2.9.10
pi#fuelightcontrol:/usr/lib/arm-linux-gnueabihf $ cd /usr/local/lib
pi#fuelightcontrol:/usr/local/lib $ ls -l
total 12120
drwxr-xr-x 3 root root 4096 Jun 14 18:17 cmake
-rw-r--r-- 1 root root 7145994 Jun 14 18:17 libxml2.a
-rwxr-xr-x 1 root root 944 Jun 14 18:17 libxml2.la
lrwxrwxrwx 1 root root 17 Jun 14 18:17 libxml2.so -> libxml2.so.2.9.14
lrwxrwxrwx 1 root root 17 Jun 14 18:17 libxml2.so.2 -> libxml2.so.2.9.14
-rwxr-xr-x 1 root root 5242072 Jun 14 18:17 libxml2.so.2.9.14
drwxr-xr-x 2 root root 4096 Jun 14 18:17 pkgconfig
drwxr-xr-x 3 root root 4096 Jun 13 21:43 python3.9
-rw-r--r-- 1 root root 205 Jun 14 18:17 xml2Conf.sh
pi#fuelightcontrol:/usr/local/lib $
The question is, what would be the best way to go about fixing the problem of the old version still being used by apt-cache policy libxml2 and other programs? I could:
Just delete /usr/lib/arm-linux-gnueabihf/libxml2.so.2.9.10 (the old one) and its symbolic link, so the system keeps searching past that point and eventually finds /usr/local/lib/libxml2.so.2.9.14 (the new one). However, something feels... off about having my libraries scattered around in different directories. My gut tells me to keep them in one place. Also, see paragraph below the next list item.
I could delete /usr/lib/arm-linux-gnueabihf/libxml2.so.2.9.10 (the old one) and its symbolic link, then move the new version into /usr/lib/arm-linux-gnueabihf to replace the old version. However, there's more libxml2 related files and 1 more symbolic link in /usr/local/lib that are not present in /usr/lib/arm-linux-gnueabihf. Do I need to move those too, or should I just move libxml2.so.2.9.14 and one (both?) of the symbolic links? If only 1 link, which?
Should I delete the files left behind after I move the required ones over? Also, see paragraph below.
What concerns me about deleting anything is if some other script comes looking for libxml2.2.9.10, can't find it, and fails. I don't know how to tell the rest of the programs that libxml2's filename is different now. I suppose both options 1 and 2 might work, but is one option a cleaner, smarter idea? I'm trying to save myself some work in the future.
Sorry this is such a small silly question. Thank you for your help!
Edit: After making backups of both directories, I tried option 1 first, then option 2. Neither changed the output of apt-cache policy libxml2 - it still says I have libxml2 2.9.10 installed, even though I deleted /usr/lib/arm-linux-gnueabihf/libxml2.so.2.9.10 and its symbolic link, rebooted, and ran sudo apt update
Here's how I updated ldconfig (same as the second link), to clear up loose ends. The link to /usr/local/lib was done for me already, which was nice.
Link to screenshot of below but in color: https://i.stack.imgur.com/7w6XR.png
pi#fuelightcontrol:/etc $ ls -l ld.so.conf
ld.so.conf ld.so.conf.d/
pi#fuelightcontrol:/etc $ cat ld.so.conf
include /etc/ld.so.conf.d/*.conf
pi#fuelightcontrol:/etc $ ls -l ld.so.conf.d
total 16
-rw-r--r-- 1 root root 12 Dec 1 2021 00-vmcs.conf
-rw-r--r-- 1 root root 109 May 14 2019 arm-linux-gnueabihf.conf
-rw-r--r-- 1 root root 41 Jun 25 2018 fakeroot-arm-linux-gnueabihf.conf
-rw-r--r-- 1 root root 44 Jun 14 19:08 libc.conf
pi#fuelightcontrol:/etc $ cat ld.so.conf.d/libc.conf
# libc default configuration
/usr/local/lib
pi#fuelightcontrol:/etc $ sudo ldconfig
pi#fuelightcontrol:/etc $ sudo ldconfig /usr/local/lib
pi#fuelightcontrol:/etc $ sudo ldconfig -n /usr/local/lib
pi#fuelightcontrol:/etc $ cat ld.so.conf.d/00-vmcs.conf
/opt/vc/lib
pi#fuelightcontrol:/etc $ cat ld.so.conf.d/arm-linux-gnueabihf.conf clear
# Multiarch support
/usr/local/lib/arm-linux-gnueabihf
/lib/arm-linux-gnueabihf
/usr/lib/arm-linux-gnueabihf
cat: clear: No such file or directory
pi#fuelightcontrol:/etc $ cat ld.so.conf.d/fakeroot-arm-linux-gnueabihf.conf
/usr/lib/arm-linux-gnueabihf/libfakeroot
pi#fuelightcontrol:/etc $
I have uninstalled python3 using brew on macOS Catalina 10.15.3:
brew uninstall python3
brew list | grep python
python#2
But it still there:
which python3
/usr/bin/python3
python3 -V
Python 3.7.3
/usr/bin/python3 -V
Python 3.7.3
ls -ltah /usr/bin/ | grep python
-rwxr-xr-x 1 root wheel 31K Jan 23 16:58 python3
lrwxr-xr-x 1 root wheel 75B Dec 16 06:20 python2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x 1 root wheel 82B Dec 16 06:20 python-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
lrwxr-xr-x 1 root wheel 76B Dec 16 06:20 pythonw2.7 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
lrwxr-xr-x 1 root wheel 82B Dec 16 06:20 python2.7-config -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7-config
lrwxr-xr-x 1 root wheel 76B Dec 16 06:20 pythonw -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/pythonw2.7
lrwxr-xr-x 1 root wheel 75B Dec 16 06:20 python2 -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
lrwxr-xr-x 1 root wheel 75B Dec 16 06:20 python -> ../../System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
It's interesting but on error it shows different location of python:
python3 -bla
Unknown option: -l
usage: /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/Resources/Python.app/Contents/MacOS/Python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.
Seems it's related to Xcode.
How to delete this version python3 and reinstall python using brew?
Update:
sudo rm -f /usr/bin/python3
rm: /usr/bin/python3: Operation not permitted
Catalina comes with python3 installed by default**. You can't delete it, because /usr/bin is on the System's read-only volume.
If you install your new python to a bin folder that comes before /usr/bin in your $PATH, then it should take precedence.
** (Well OK, the first time you run it, you have to install Xcode command line tools to make it work. But that file itself is a system install.)
When executing a Python 3 script in a symbolic directory, I want to get the non-dereferenced path of the current directory. However, the default behavior of pathlib returns the derefenced path:
$ mkdir test1
$ ln -s test1 test2
$ cd test2
$ pwd
/home/myuser/test2
$ ipython3
Python 3.7.0 (default, Oct 9 2018, 10:31:47)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.1.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from pathlib import Path
In [2]: str(Path.cwd())
/home/myuser/test1
The behavior I want is to get "/home/myuser/test2" as that's where the 'script' (interpreter in this case) was executed from, preferably using pathlib.
Use os.getenv('PWD'):
Directories:
$ ls -l
total 1
drwxr-xr-x+ 1 cody agroup 0 Dec 11 15:23 dir1
lrwxrwxrwx 1 cody agroup 4 Dec 11 15:23 dir2 -> dir1
Result from dir2:
>>> str(Path.cwd())
'/home/cody/so/dir1'
>>> os.getenv('PWD')
'/home/cody/so/dir2'
I am trying to run Quartus 13.0 in the following machine:
parrot 4.18.0-parrot10-amd64 #1 SMP Debian 4.18.10-1parrot10 (2018-10-06) x86_64 GNU/Linux.
I have finished installing Quartus 13.0 and when I try to execute it I get this error:
quartus: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory
I have read all the related questions in stack overflow and other websites but no one worked for me.
When looking for that file, I found it. I have tried to do a hard link but it doesn't work either. Search results:
┌─[pepbd#parrot]─[~]
└──╼ $ls -ld $(locate -r libpng.*\.so.*)
lrwxrwxrwx 1 root root 19 nov 19 17:09 /usr/lib/x86_64-linux-gnu/libpng16.so.16 -> libpng16.so.16.34.0
-rw-r--r-- 1 root root 210864 jul 10 13:17 /usr/lib/x86_64-linux-gnu/libpng16.so.16.34.0
-rw-r--r-- 1 root root 18272 oct 14 21:59 /usr/lib/x86_64-linux-gnu/vlc/plugins/codec/libpng_plugin.so
I had the same problem with Quartus Prime 18 on Ubuntu. This worked for me (run as sudo):
wget -q -O /tmp/libpng12.deb http://mirrors.kernel.org/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1_amd64.deb \
&& dpkg -i /tmp/libpng12.deb \
&& rm /tmp/libpng12.deb
I don't know what happened to this Linux machine, but now it is not recognizing many Unix commands anymore
~ # uname -a
Linux mpc8306som 2.6.34.10-WR4.3.0.0_standard #9 PREEMPT Mon Jun 17 10:55:18 CST 2013 ppc GNU/Linux
~ # echo $PATH
/usr/local/sbin:/sbin:/usr/sbin:/bin:/usr/bin
~ # cal
May 2014
Su Mo Tu We Th Fr Sa
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
~ # which
-sh: which: not found
~ # whereis
-sh: whereis: not found
~ # find / -iname "whereis*" -print
~ # find / -iname "which*" -print
~ # apt-get
-sh: apt-get: not found
~ # yum
-sh: yum: not found
How can I fix these problems?
This is a Wind River Linux system — their version 4.3 small (standard).
Reinstall?
Unless it is really required, I try not to fix broken machines too long. I make it easy to deploy new ones and recycle when shit hits the fan...
But then I also usually run virtualized systems and snapshot working setups.