Running python script without libraries installed

I apologize in advance, this is probably a stupid question, but I am confused and need a straightforward answer.

I have a Python script running with functions scipy

and numpy

, and I need to run it on a machine with Python installed, but without modules scipy

and numpy

. How should I do it? Is this the .pyc

answer or should I do something more complex?

Notes:

+3


source to share


3 answers


Python first "compiles" the program to bytecode, and then outputs that bytecode through the interpreter.

So, if your code is all Python code, you can generate bytecode once and then use it at runtime in Python. In fact, I've seen projects like this where a developer has just reviewed a bytecode specification and implemented a bytecode parsing engine. It is very lightweight so it is useful for eg "Python on a Chip" etc.



The problem is with external libraries not fully written in Python (e.g. numpy, scipy).

Python provides a C-API that allows you to create (using C / C ++ code) objects that appear as Python objects in it. This is useful for speeding up work, interacting with hardware, using C / C ++ libs.

+1


source


It's impossible.

A pyc

-file is nothing more than a python file compiled to byte code. It does not contain any modules that this file imports!



Also, the module numpy

is an extension written in C (and some Python). An essential part of this is the shared libraries that are loaded into Python at runtime. You need those for numpy to work!

+2


source


Take a look at Nuitka . If you can compile your code (not necessarily a possible or easy task), you get what you want.

+1


source







All Articles