I have working Python script using scipy
and numpy
functions and I need to run it on the computer with installed Python but without modules scipy
and numpy
. How should I do that? Is .pyc
the answer or should I do something more complex?
Notes:
py2exe
. I am aware of it but it doesn't fit to the problem.py2exe is a Python extension which converts Python scripts (. py) into Microsoft Windows executables (.exe). These executables can run on a system without Python installed. It is the most common tool for doing so.
It is not possible. A pyc -file is nothing more than a python file compiled into byte-code. It does not contain any modules that this file imports!
If you are on a system where you don't want to or cannot install a Python interpreter, but you'd like to practice your Python skills, or just want to quickly test an idea, online Python interpreters are a great choice for you. Using an online Python interpreter you can simply run Python code in your web browser.
It is not possible.
A pyc
-file is nothing more than a python file compiled into byte-code. It does not contain any modules that this file imports!
Additionally, the numpy
module is an extension written in C (and some Python). A substantial piece of it are shared libraries that are loaded into Python at runtime. You need those for numpy to work!
Python first "compiles" a program into bytecode, and then throws this bytecode through an interpreter.
So if your code is all Python code, you would be able to one-time generate the bytecode and then have the Python runtime use this. In fact I've seen projects such as this, where the developer has just looked through the bytecode spec, and implemented a bytecode parsing engine. It's very lightweight, so it's useful for e.g. "Python on a chip" etc.
Problem comes with external libraries not entirely written in Python, (e.g. numpy, scipy).
Python provides a C-API, allowing you to create (using C/C++ code) objects that appear to it as Python objects. This is useful for speeding things up, interacting with hardware, making use of C/C++ libs.
Take a look at Nuitka. If you'll be able to compile your code (not necessarily a possible or easy task), you'll get what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With