1

I have multiple Python versions installed (2.7 and 3.4) I want to run a .pyc with specified version of Python

#! C:\python34\python
import sys
print("Hello",sys.version.split()[0])
input()

This sheebang works fine on Windows because I use pylauncher So I can compile like that

c:\python34\python -m compileall print.py -b

But the sheebang is not recognized when I execute the pyc file.

This works, but I wouldn't like to repeat the C:\python34\python Because the current script will be already running under the Python version I asked in the shebang. Therefore I would like to make the sub program start with the same version of the Python.

So far, I tried:

#! C:\python34\python
import os
os.system("C:\python34\python print.pyc")

This would be perfect, but doesn't like pyc files. And the following doesn't works either:

exec( open('print.pyc').read() )

Does someone knows how to call the pyc files in the code?

6
  • 1
    have you tried: os.system("C:\\python34\\python print.pyc") ? Commented May 20, 2014 at 16:15
  • No because that I want is not to repeat C:\python34\python since my shebang works fine. I want to say: Run that pyc file in the same already running python's version. Commented May 20, 2014 at 16:21
  • 1
    Can you formulate your question better? You said : os.system("C:\python34\python print.pyc") would be fine but it doesn't like pyc. While it clearly doesn't have the right backslashes (\\ instead of \ ) in the string. Commented May 20, 2014 at 16:27
  • It works with "C:\\python34\\python print.pyc", with "C:\\\python34\\\python print.pyc", with "C:/python34/python print.pyc" and with "C:\python34\python print.pyc". But since the path is ok whith the shebang, I dan't want to repeat it. Commented May 20, 2014 at 19:33
  • Have you tried os.system(sys.executable+" print.pyc") ? sys.executable is path to python executable that is running just now. Commented May 20, 2014 at 20:34

1 Answer 1

2
#! C:\python34\python
import print # imports print.pyc


#now you can use the pyc as a module. 
DoSomething()
Sign up to request clarification or add additional context in comments.

3 Comments

Yes, this is perfect:
@Baghera, if this answer is what you were looking for, please accept it.
Yes, this is perfect:<br/> #! C:\python34\python import print This is the run.py file.<br/> It starts the print.pyc application with the Python's version I want to, because I compiled this application with.<br/> Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.