Python Forum

Full Version: Setting Up Python on New Debian 12 Install
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I have recently installed Debian 12 on my main desktop machine.

Due to past unhappy experiences I do not want to monkey with the default Python installed (3.11). So I have been reading through Snippsat's and other tutorials to have a better chance of getting virtual Python enviroments right the first time.

I would like to be able to create virtual enviroments for 2.7.9, 2.7.16, 2.7.17, 3.4.2, 3.6.9, 3.7.3, and, of course 3.12. I have Python programs written in these versions running on a bunch of older hardware, mostly RPi 2's, 3's and 4's. It would be nice to be able to modify and test my old programming on my new Debian 12 install. Some of the programming that I use a lot I will port over to Python 3.11 and/or 3.12, sot sure which yet.

I see that the tutorials have a few years on them, is the anything new that is not in the tutorials that I should be aware of?

Any other advice?

By the way, I am hacker clobber it together and get it running kind of programmer, not an ace at all.

Thanks,
JP.
Follow this Install Pyenv and Pyenv-Virtualenv (Linux/Debian)
You can do as in link or this like this,so vim ~/.bashrc this open the file and add these lines last in file.
# Add pyenv to PATH and initialize it
export PATH="$HOME/.pyenv/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Quote:You can do as in link or this like this,so vim ~/.bashrc

I'll check it out. I'm hesitant to admit it, I don't know why it happened, but about 20 years ago I switched from vi to nano. Used vi all through the '80's and '90's, I think. Those IBM mainframe, AIX, early Debian days were a long time ago, memory not as good as it used to be. Using nano in Midnight Commander is just old habit now.
(Jun-23-2024, 07:10 PM)jogl Wrote: [ -> ]
Quote:You can do as in link or this like this,so vim ~/.bashrc

I'll check it out. I'm hesitant to admit it, I don't know why it happened, but about 20 years ago I switched from vi to nano. Used vi all through the '80's and '90's, I think. Those IBM mainframe, AIX, early Debian days were a long time ago, memory not as good as it used to be. Using nano in Midnight Commander is just old habit now.

I think it's mostly preference. I use nano. I find it easier to use.
Hey JP, it sounds like you've got quite a setup going on! Sticking with the default Python version on Debian is a good call. For managing multiple Python versions, you might want to check out tools like pyenv. They make switching between different Python versions and creating virtual environments super straightforward. The tutorials you mentioned should still be relevant, but using pyenv could greatly simplify your workflow.
Finally getting back to this.

I'm a little confused:

(py2_7_17) jogl@D40:~/py2_7_17$ nano /home/jogl/python/wg3.py
(py2_7_17) jogl@D40:~/py2_7_17$ pyenv versions
  system
* 2.7.17 (set by /home/jogl/py2_7_17/.python-version)
  3.12.7
(py2_7_17) jogl@D40:~/py2_7_17$ python /home/jogl/python/wg3.py
  File "/home/jogl/python/wg3.py", line 57
    print '\n'
    ^^^^^^^^^^
SyntaxError: Missing parentheses in call to 'print'. Did you mean print(...)?
(py2_7_17) jogl@D40:~/py2_7_17$ 
Why am I getting the print format error. Am I not running 2.7.17?

Thanks,
JP.

P.S.: Now I see this:

(py2_7_17) jogl@D40:~/py2_7_17$ python
Python 3.12.7 (main, Oct 31 2024, 14:43:01) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
(py2_7_17) jogl@D40:~/py2_7_17$
Well, I haven't set the 2.7.17 environment correctly. Hmm.

JP.
So, how do I get:

python -m venv [my_virtual-env]
to create a python 2 enviroment?
OMG

Now I'm searching for a way to get rid of all this virtual environment crap without having to re-install the O/S.

This has been a nightmare.
(Nov-01-2024, 02:45 PM)jogl Wrote: [ -> ]Why am I getting the print format error. Am I not running 2.7.17?
You most of course test not assume that you run 2.7.
If setup of pyenv is correct is easy to change Python versions(which is the point of pyenv).
tom@tom-VirtualBox:~$ python --version
Python 3.11.3
tom@tom-VirtualBox:~$ pyenv global 2.7.18
# Now run 2.7
tom@tom-VirtualBox:~$ python --version
Python 2.7.18
# Then will of course old print work
tom@tom-VirtualBox:~$ python
Python 2.7.18 (default, Mar 18 2022, 14:15:22) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print 'hello world'
hello world
>>> exit()
Over is all that needed to use 2.7,can make virtual environment like this.
tom@tom-VirtualBox:~$ pyenv virtualenv 2.7.18 2_env
tom@tom-VirtualBox:~$ pyenv activate 2_env
(2_env) tom@tom-VirtualBox:~$ python --version
Python 2.7.18
(2_env) tom@tom-VirtualBox:~$ python
Python 2.7.18 (default, Mar 18 2022, 14:15:22) 
[GCC 7.3.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print 'a car'
a car
Hey Snippsat:

What O/S are you running? Is it a virtual machine?

I have a qemu/kvm server running. Starting to think that virtual machines might work better for me than virtual python environments. Actually there is no better, I will waste no more time on venv.
Pages: 1 2