How can I run a Python project on another computer without installing anything on it?
I see two options.
Use an online IDE and Python Interpreter (assuming you did not have internet for downloading Python, but do have internet in general). I suggest replit.
Use a portable version of Python. Those are available in the official website and are called "Windows embeddable package". You can test downloading it to a usb, and running it in some computer without Python; it should work.
Running python script without installed libraries
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.
Run python script with module/ modules already imported
I think what you'r looking for is the interactive mode:
-i
When a script is passed as first argument or the-c
option is used, enter interactive mode after executing the script or the command
So just use python -i cls.py
in your batch file. This would import your Python file and stay in the Python interpreter prompt. You could then just call cls()
because it's already imported.
Alternatively, you could set the environment variable PYTHONSTARTUP
in your batch file:
If this is the name of a readable file, the Python commands in that file are executed before the first prompt is displayed in interactive mode. The file is executed in the same namespace where interactive commands are executed so that objects defined or imported in it can be used without qualification in the interactive session.
Related Topics
Checking If a Button Has Been Pressed in Python
Converting Pandas Column of Comma-Separated Strings into Integers
How to Map True/False to 1/0 in a Pandas Dataframe
How to Convert Data from Txt Files to Excel Files Using Python
Webdriverexception: Message: Unknown Error: Chrome Failed to Start: Crashed
How to Save a Pandas Dataframe Table as a Png
How to End Program If Input == "Quit" With Many If Statements
How to Remove the Double Quote When the Value Is Empty in Spark
Pytest Cannot Import Module While Python Can
Python Opencv Load Image from Byte String
Removing Backslashes from a String in Python
Print All Number Divisible by 7 and Contain 7 from 0 to 100
Use Variable as Key Name in Python Dictionary
How to Plot Multiple Pandas Columns
How to Sum Dictionaries Values With Same Key Inside a List