Python Forum
Virtual environment and upgrading python 3.5 to 3.9
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Virtual environment and upgrading python 3.5 to 3.9
#1
I have python 3.5.2 with a single virtual environment on linux mint 18, which also has a system 2.7.12. I have installed a number of packages using pip from the VE, and it all seems to work fine. That was a while ago, I've forgotten how I did it other than it seemed quite stressful, and my notes from the time are obviously about a new python3 installation, not a second one.

I now want to go up to something higher than 3.5 (for some specific packages, and f strings look useful). 3.9 is now available in the standard repo, so I might as well go to the latest. I'm not a developer, just a hobbyist, there's no need for me to keep 3.5 going once 3.9 is working.

I've being trying to find out how to do it, and the documentation online doesn't address what I thought was my specific problem, of making a new VE and putting 3.9 in it, to keep things separate from 2.7 and 3.5. After a week of puzzling, I'm now beginning to think my original conception was wrong. I thought that the VEs isolated different versions of python and their packages from each other. I'm starting to think that they isolate the packages alone.

If my new conception is correct, then I should simply apt-get install python3.9. I'm reluctant to simply do this as I don't want to break my main machine.

Does the installation of 3.9 make the python3 command use 3.9 instead of 3.5? or
Do I need to make a new VE once 3.9 is installed? and
If so, how does it get pointed at 3.9?

This is one of those things that's presumably so obvious that it's not documented in a way I can understand. While I'm quite capable of writing quite complex programs once 'hello world' is working, I'm totally capable of messing up the programming environment so that I can't even run that. I notice various files in the bin of my VE have file names like xx2.7, xx3 and xx3.5, which suggests it does get 'pointed at' the relevant python version at some stage during installation.
Reply
#2
(Jan-22-2021, 05:34 PM)NeilUK Wrote: If my new conception is correct, then I should simply apt-get install python3.9. I'm reluctant to simply do this as I don't want to break my main machine.
Can look at this Simple Python Version Management
It's a safe way,and can switch seamlessly between any Python versions or Anaconda/PyPy ect...
(Jan-22-2021, 05:34 PM)NeilUK Wrote: Does the installation of 3.9 make the python3 command use 3.9 instead of 3.5? or
If install yourself and not use method over there can be step like alias or may not be needed.
A Guide to Upgrade Your Python to 3.9
Quote:I thought that the VEs isolated different versions of python and their packages from each other. I'm starting to think that they isolate the packages alone.
The main purpose of Python virtual environments is to create an isolated environment for Python projects not Python version.
This means that each project can have its own dependencies,regardless of what dependencies every other project has.

For a good editor can also look at VS Code from start,
it also make it easier to switch between Python version or virtual environment.
Reply
#3
Thanks for your reply, and I don't wish to appear ungrateful, but installing and using yet another thing which I don't understand would take me in the wrong direction.

Perhaps my original question was unclear. I have python 3.5, I want to replace it by python 3.9. How do I upgrade, given that I was persuaded to create a virtual environment for it when I installed 3.9? I would rather not have, I don't need multiple environments or versions, but the warnings about messing with linux's use of python were very loud. I use Idle, I don't need dev tools like pycharm or eclipse, I'm not a dev.

The simplest solution for me would (that I understand) be to uninstall everything 3.5 related and install 3.9 fresh, delete all the files I can find relating to the old virtual environment, if I can be convinced that I can remove all traces of 3.5 that might interfere with the future 3.9. I can find plenty of advice about how to install from scratch, and none about how to upgrade.

Does standard operating procedure for python cater for what should be simple stuff like replace (old version) with (new version)? Or do I really need to shave a yak to get there?
Reply
#4
(Jan-24-2021, 05:39 AM)NeilUK Wrote: Perhaps my original question was unclear. I have python 3.5, I want to replace it by python 3.9.

It would be common to have both versions installed simultaneously. So rather than "replace", you just have both and run the one you want. The nice thing is that you can keep using 3.5 while you test 3.9 for your purposes.

Quote:How do I upgrade, given that I was persuaded to create a virtual environment for it when I installed 3.9? I would rather not have, I don't need multiple environments or versions, but the warnings about messing with linux's use of python were very loud.

Normal way would be to install 3.9. Then create your virutal env for 3.9. You can read the list of packages installed in your previous venv and then ask it to install those in your new one. Something like...

# activate your original venv
$ . /path/to/3.5venv/bin/activate
(3.5venv) $ pip freeze > /tmp/requirements.txt  # get list of packages in the old environment
(3.5venv) $ deactivate
$ python3.9 -m venv /path/to/3.9venv            # make the new 3.9 venv
$ . /path/to/3.9venv/bin/activate
(3.9venv) $ pip install -r /tmp/requirements.txt  # install the same packages in the new environment
Quote:The simplest solution for me would (that I understand) be to uninstall everything 3.5 related and install 3.9 fresh, delete all the files I can find relating to the old virtual environment, if I can be convinced that I can remove all traces of 3.5 that might interfere with the future 3.9. I can find plenty of advice about how to install from scratch, and none about how to upgrade.

The idea of virtual environments is that they are independent. Removing one won't make any other ones run better.


Quote:Does standard operating procedure for python cater for what should be simple stuff like replace (old version) with (new version)? Or do I really need to shave a yak to get there?

I'd say that's more a question for your specific operating system and how it manages applications. The individual python versions don't care what other versions are installed, and most operating systems and their package managers easily support multiple installed versions. It would be very limiting to upgrade versions all in one go, without any testing. Instead it would be expected that the new version was installed and tested while the old version was still being used.
Reply
#5
(Jan-24-2021, 05:39 AM)NeilUK Wrote: if I can be convinced that I can remove all traces of 3.5 that might interfere with the future 3.9.
You should never remove(update ok) Python versions that comes default with with linux,
as Linux can use dependencies from these Python version.
Many have messed up OS trough the years doing this.

So you install new versions and if not use pyenv,then follow links with eg deadsnakes/ppa or search.
Linux Mint 18 start to get old,so you should consider to upgrade Linux Mint 20.1 has Python 3.8.5 as default Python version.
Quote:Mint 18.3 Long term support release (LTS), supported until April 2021.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with creating folder and "virtual environment" AudunNilsen 1 171 Mar-21-2024, 04:41 AM
Last Post: deanhystad
  Best practice on using virtual environments in Python bytecrunch 6 644 Feb-14-2024, 03:22 PM
Last Post: snippsat
  Virtual Env changing mysql connection string in python Fredesetes 0 324 Dec-20-2023, 04:06 PM
Last Post: Fredesetes
  Installing python packages in a virtual environment Led_Zeppelin 1 712 Aug-15-2023, 08:18 PM
Last Post: deanhystad
  Understanding venv; How do I ensure my python script uses the environment every time? Calab 1 2,158 May-10-2023, 02:13 PM
Last Post: Calab
  Python development environment standenman 3 1,523 May-04-2023, 07:24 PM
Last Post: snippsat
  Problem with virtual environment standenman 2 945 Feb-23-2023, 07:09 PM
Last Post: standenman
Question Virtual Environment (using VS Code) Ashcora 4 12,503 Feb-15-2023, 07:17 PM
Last Post: snippsat
  Python Scripting Environment jpotter0 1 1,619 Nov-19-2022, 03:07 PM
Last Post: snippsat
  Upgrading from 2 to 3 and having file write problems KenHorse 2 1,430 May-08-2022, 09:47 PM
Last Post: KenHorse

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020