Jump to content

Recommended Posts

How do I tell a Python script to use a particular version?
    
How do I, in the main.py module (presumably), tell Python which interpreter to use?
What I mean is: if I want a particular script to use version 2 of Python to interpret the entire program, how do I do that?

I know that you can run your programs/scripts with different versions by typing "Py -2 file.py" or "Py -3 file.py", but is there any way to run...

 

 

btw  if i do so - it fails


 py -2 cp1.py

 

martin@linux-3645:~/_dev_/python>  py -2 cp1.py
If 'py' is not a typo you can use command-not-found to lookup the package that contains it, like this:
    cnf py
martin@linux-3645:~/_dev_/python>




The script itself can't decide that. You either have to run the file with the right python version, or turn the file into a shell executable (chmod +x) with a shebang of one of

#!/usr/bin/env python2
#!/usr/bin/env python3
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.