# Command seemingly using wrong version of python when using update-alternatives

**URL:** <https://discussion.fedoraproject.org/t/command-seemingly-using-wrong-version-of-python-when-using-update-alternatives/87391>\
**Category:** Ask Fedora\
**Tags:** f38, python\
**Created:** [August 12, 2023, 5:52pm UTC](https://discussion.fedoraproject.org/t/command-seemingly-using-wrong-version-of-python-when-using-update-alternatives/87391 "2023-08-12T17:52:44Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![tejasarunkumar](https://avatars.discourse-cdn.com/v4/letter/t/b193c8/32.png) [@tejasarunkumar](https://discussion.fedoraproject.org/u/tejasarunkumar)\
**Post date:** [August 12, 2023, 5:52pm UTC](https://discussion.fedoraproject.org/t/command-seemingly-using-wrong-version-of-python-when-using-update-alternatives/87391/1 "2023-08-12T17:52:44Z")

</div>

Hey there! I’m trying to run [riscv-dc](https://github.com/chipsalliance/riscv-dv) using the python generator. For this, one of the requirements are [pyvsc](https://github.com/fvutils/pyvsc) , which wouldn’t install using the bundled python 3.11 with fedora 38, so I had to use update-alternatives to install python 3.9(as shown in the image)

 ![image](https://us1.discourse-cdn.com/fedoraproject/original/3X/e/1/e17d7f7b62fba3a60bb5ae23d8417262db704863.png)  
When I try to run the python script, I get an error as shown below:  
 ![image](https://us1.discourse-cdn.com/fedoraproject/original/3X/a/2/a27d90e1bbda75bec56478fc8d7d74fdee987019.png)  
Even though I explicitly used python, the error message seems to suggest that the command is using python3 instead of python.  
 ![image](https://us1.discourse-cdn.com/fedoraproject/original/3X/6/2/623fe736d05af281cc9ab2bb32182a2d2e29e1df.png)  
The package vsc is clearly present, as demonstrated.  
Any help with getting this to work would be much appreciated.  
PS - Using a virtual environment is not an option.

---

<div class="post-metadata">

**Author:** ![jakfrost](https://sea1.discourse-cdn.com/fedoraproject/user_avatar/discussion.fedoraproject.org/jakfrost/32/30655_2.png) [@jakfrost](https://discussion.fedoraproject.org/u/jakfrost)\
**Post date:** [August 12, 2023, 6:17pm UTC](https://discussion.fedoraproject.org/t/command-seemingly-using-wrong-version-of-python-when-using-update-alternatives/87391/2 "2023-08-12T18:17:58Z")

</div>

You may try to downgrade your python package to the desired releasever. For instance F37 is where Python 3.11 is used so maybe the command would be `sudo dnf downgrade python --releasever=37`

---

<div class="post-metadata">

**Author:** ![barryascott](https://avatars.discourse-cdn.com/v4/letter/b/db3279/32.png) [@barryascott](https://discussion.fedoraproject.org/u/barryascott)\
**Post date:** [August 12, 2023, 8:11pm UTC](https://discussion.fedoraproject.org/t/command-seemingly-using-wrong-version-of-python-when-using-update-alternatives/87391/3 "2023-08-12T20:11:43Z")

</div>

Please post text as preformated text and not screen shots.

2 thoughts.

Does it work if you use

```auto
python3.8 run.py 

```

If not I would add a folder to the front of the PATH that has  
symlinks for python and python3 that point to python3.8.

---

<div class="post-metadata">

**Author:** ![tejasarunkumar](https://avatars.discourse-cdn.com/v4/letter/t/b193c8/32.png) [@tejasarunkumar](https://discussion.fedoraproject.org/u/tejasarunkumar)\
**Post date:** [August 13, 2023, 7:09am UTC](https://discussion.fedoraproject.org/t/command-seemingly-using-wrong-version-of-python-when-using-update-alternatives/87391/4 "2023-08-13T07:09:12Z")

</div>

I tried downgrading to F36, as pyvsc/boolector is only validated till python 3.10. I got the following error:

```auto
- Curl error (6): Couldn't resolve host name for https://mirrors.fedoraproject.org/metalink?repo=fedora-cisco-openh264-36&arch=x86_64 [Could not resolve host: mirrors.fedoraproject.org]

```

I tried fixing it by doing what’s mentioned [here](https://www.codingpointer.com/blogs/curl-error-could-not-resolve-hostname-fedora) , but it didn’t work.

---

<div class="post-metadata">

**Author:** ![tejasarunkumar](https://avatars.discourse-cdn.com/v4/letter/t/b193c8/32.png) [@tejasarunkumar](https://discussion.fedoraproject.org/u/tejasarunkumar)\
**Post date:** [August 13, 2023, 7:13am UTC](https://discussion.fedoraproject.org/t/command-seemingly-using-wrong-version-of-python-when-using-update-alternatives/87391/5 "2023-08-13T07:13:35Z")

</div>

Right, sorry about the screenshots. I was having trouble figuring out what parts of the output were relevant.  
i) No, it doesn’t work if I use `python3.9` instead of `python`  
ii) Could you please elaborate on what this means? I looked up what symlinks are, and I already have the location of both python installs in the path.

---

<div class="post-metadata">

**Author:** ![barryascott](https://avatars.discourse-cdn.com/v4/letter/b/db3279/32.png) [@barryascott](https://discussion.fedoraproject.org/u/barryascott)\
**Post date:** [August 13, 2023, 8:02am UTC](https://discussion.fedoraproject.org/t/command-seemingly-using-wrong-version-of-python-when-using-update-alternatives/87391/6 "2023-08-13T08:02:37Z")

</div>

Seems that you are new to using unix systems.

Use man to read up about the `ln -s` command.

The best clue is the error message clearly shows that python3 is the command used, not python.

I suspect that you have not install vsc for the default python3.

Also seems you network is not setup correctly which is why curl failed.  
Is this on a company network? Is there firewall blocking your work?

What is the output of

```auto
resolvectl

```

Back to the symlinks. Code often refers to python using python3 not python.  
That means that you need to setup python3 to run your preferred version of python.

Having said all that it is often the case that code that works with 3.10 will work with 3.11. I have many versions of python installed on fedora 38 systems.  
Then I run the version I need for testing code.

Another thought is that you could use a venv built with your preferred version of python. Then run the tool in from the activated venv.

---

<div class="post-metadata">

**Author:** ![tejasarunkumar](https://avatars.discourse-cdn.com/v4/letter/t/b193c8/32.png) [@tejasarunkumar](https://discussion.fedoraproject.org/u/tejasarunkumar)\
**Post date:** [August 13, 2023, 8:32am UTC](https://discussion.fedoraproject.org/t/command-seemingly-using-wrong-version-of-python-when-using-update-alternatives/87391/7 "2023-08-13T08:32:15Z")

</div>

Yes, this is my first time with a unix system.  
Installing vsc for python 3.11 is not possible, as far as I know. [Here](https://github.com/Boolector/boolector/issues/207)’s an issue I found which goes into this. boolector is a pre requisite for vsc, and it wouldn;t install with python 3.11, which is why I tried using another version of python, one that had been validated to work with the packages i needed.  
Output of resolvectl:

```auto
Global
         Protocols: LLMNR=resolve -mDNS -DNSOverTLS DNSSEC=no/unsupported
  resolv.conf mode: stub

Link 2 (wlp1s0)
    Current Scopes: DNS LLMNR/IPv4 LLMNR/IPv6
         Protocols: +DefaultRoute LLMNR=resolve -mDNS -DNSOverTLS DNSSEC=no/unsupported
Current DNS Server: 2401:4900:50:9::280
       DNS Servers: 125.22.47.125 203.145.160.4 2401:4900:50:9::66 2401:4900:50:9::280

```

I’ve also tried setting up a virtual environment as detailed [here](https://developer.fedoraproject.org/tech/languages/python/multiple-pythons.html), but didn’t have much luck with that either.

Edit: Running the downgrade command worked fine for `--releasever=37` but not for `releasever=36`

---

<div class="post-metadata">

**Author:** ![jakfrost](https://sea1.discourse-cdn.com/fedoraproject/user_avatar/discussion.fedoraproject.org/jakfrost/32/30655_2.png) [@jakfrost](https://discussion.fedoraproject.org/u/jakfrost)\
**Post date:** [August 13, 2023, 11:15am UTC](https://discussion.fedoraproject.org/t/command-seemingly-using-wrong-version-of-python-when-using-update-alternatives/87391/8 "2023-08-13T11:15:26Z")

</div>

Hello I said F37 has Python 3.11. You should use the docs from Fedora’s site since it is Fedora we are working on here. The downgrade of the package was supposed to f37 Python package. You should have started by removing the Python 3.11 you installed that didn’t help you with your compilation problem, then done a `sudo dnf update` to make sure your system was sound after removal of the package. Then use the instruction I quoted. You can only downgrade some packages so far.  
Okay, so my bad, you want Python 3.9. Please see theses doc’s, they are about doing just what you are asking with Python 3.9 [https://developer.fedoraproject.org/tech/languages/python/python-installation.html](https://developer.fedoraproject.org/tech/languages/python/python-installation.html)

---

<div class="post-metadata">

**Author:** ![barryascott](https://avatars.discourse-cdn.com/v4/letter/b/db3279/32.png) [@barryascott](https://discussion.fedoraproject.org/u/barryascott)\
**Post date:** [August 13, 2023, 7:53pm UTC](https://discussion.fedoraproject.org/t/command-seemingly-using-wrong-version-of-python-when-using-update-alternatives/87391/9 "2023-08-13T19:53:10Z")

</div>

Where are you getting vsc and boolector from? They do not seem to be on PyPI, at least with those names.

I recommend you stick to Fedora 38. Trying to downgrade is just going make it harder to help you.

We cannot help you if all the info you give us is “it failed”.

What exact did you do to setup a venv and what exact happened?  
Show all the commands you are running with all the output.

It seems your DNS issue is solved as you say you could downgrade to 37,  
something I have never every done am surprised worked.

---

<div class="post-metadata">

**Author:** ![tejasarunkumar](https://avatars.discourse-cdn.com/v4/letter/t/b193c8/32.png) [@tejasarunkumar](https://discussion.fedoraproject.org/u/tejasarunkumar)\
**Post date:** [August 14, 2023, 5:08am UTC](https://discussion.fedoraproject.org/t/command-seemingly-using-wrong-version-of-python-when-using-update-alternatives/87391/10 "2023-08-14T05:08:55Z")

</div>

Using `sudo rm /usr/bin/python3` and `sudo ln -s /usr/bin/python3.9 /usr/bin/python3` seems to have done the trick. I realise that this may not be the best way to do this, but I don’t mind it for now, as I’m using fedora only for this one specific task.

The pip packages are called pyvsc and pyboolector.

My understanding is that `sudo dnf downgrade python --releasever=37` downgrades only python to that of fedora37’s version.  
It worked when I tried it, and for the record, I tried it before I tried `--releasever=36`.

Thank you and @jakfrost for your help and patience. I’ll mark one of your earlier answers suggesting symlinks as the solution.

---

<div class="post-metadata">

**Author:** ![barryascott](https://avatars.discourse-cdn.com/v4/letter/b/db3279/32.png) [@barryascott](https://discussion.fedoraproject.org/u/barryascott)\
**Post date:** [August 14, 2023, 5:19pm UTC](https://discussion.fedoraproject.org/t/command-seemingly-using-wrong-version-of-python-when-using-update-alternatives/87391/11 "2023-08-14T17:19:10Z")

</div>

The fedora system itself depends on python. If you downgrade python you risk breaking Fedora.

> [@tejasarunkumar](#):
>
> Using `sudo rm /usr/bin/python3` and `sudo ln -s /usr/bin/python3.9 /usr/bin/python3` seems to have done the trick. I realise that this may not be the best way to do this, but I don’t mind it for now, as I’m using fedora only for this one specific task.

And this is also risking break Fedora.

I would use a venv to solve this type of problem without risking the OS breaking.

I would guess commands like this:

```auto
sudo dnf install python3.9
example/bin/python -m pip install pyvsc pyboolector
example/bin/python run.py ...

```

I tried to pip install but its trying to use cmake I guess and other build tools that I do not have installed. I’m sure you have solved that part of the problem.

---

<div class="post-metadata">

**Author:** ![tejasarunkumar](https://avatars.discourse-cdn.com/v4/letter/t/b193c8/32.png) [@tejasarunkumar](https://discussion.fedoraproject.org/u/tejasarunkumar)\
**Post date:** [August 15, 2023, 1:30pm UTC](https://discussion.fedoraproject.org/t/command-seemingly-using-wrong-version-of-python-when-using-update-alternatives/87391/12 "2023-08-15T13:30:33Z")

</div>

Yes, I’m considering setting up something like conda for this as a permanent fix, but it will have to wait till the weekend. In the mean time, everything’s seemingly normal and run.py works as expected.  
I’ll live with the risk in the mean time. Like i said, I only use fedora for this one specific task. Thanks again for your help and suggestions.
