Python Forum
where to get portable Python for Linux (Fedora)?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
where to get portable Python for Linux (Fedora)?
#1
My C++ project needs Python to do some simple things (I/O, batch string find/replacement...). I want my program self-contained and do not rely on the environment of the target computer for Python.

I have included Windows Python distribution in my project. My C++ project will use this included version of Python (to execute attached small python programs/files) no matter there is another Python installation on the PC or not. So my program can run on any target PCs that may have a different version of Python installed or may have no Python installed at all.

My program can also run on Linux. Now, I need to do the same thing for Linux to include Linux Python in my C++ program. I have downloaded and built/made the Python 3.8.6 source tarball. But I don't know which files/folders are the distribution I should copy to my project. Or is there any ready-to-go compressed file I can download somewhere?

Note:

What I want is to include a Python environment (its interpreter and main modules/packages) in my program. When I call "python aPythonFile" from my C++, the Python interpreter used is the one included inside my C++ program's distribution. I don't want to use the unknown version of the Python interpreter installed with the Linux system. I don't want to pack my python scripts with the Python interpreter as well because I may add more scripts later on.

What I want is a kind of portable Python environment/installation (for Linux ONLY) that can be distributed with my C++ program. It will be used by my C++ program to run/execute my small python programs/files.
Reply
#2
read this and use as a guide for packaging your application: https://packaging.python.org/overview/
FYI: there are very reliable binary packages available for all python OS versions here: https://www.python.org/downloads/ it's not necessary to rebuild from scratch.
python001 likes this post
Reply
#3
What does your application do? Using Docker to package your app may be an option (of course, users would need Docker!).
python001 likes this post
Reply
#4
There are serval way's for this,from doc Embedding Python in C++.
Libraries to look at pybind11, Boost.Python, Nuitka...ect

python001 Wrote:What I want is to include a Python environment (its interpreter and main modules/packages) in my program. When I call "python aPythonFile" from my C++, the Python interpreter used is the one included inside my C++ program's distribution. I don't want to use the unknown version of the Python interpreter installed with the Linux system.
Pyinstaller work fine for this,can create a standalone version with Python interpreter included.
A simple example using system call python from C++.
# meaning.py
def foo(arg):
    return f'Meaning of life number is <{arg}>'

print(foo(42))
// meaning.cpp
#include<iostream> 
using namespace std; 

int main() 
{ 
 	system("python meaning.py"); 
    return 0; 
}
Output:
Running] g++ -o meaning "e:\div_code\c++\meaning.cpp" && meaning Meaning of life number is <42> [Done] exited with code=0 in 1.566 seconds
So it works,now using a exciting Python 3.8 interpreter.
A standalone version made with pyintaller would i call like this,
so here is meaning a stand alone version not needing a Python interpreter.
// meaning.cpp
#include<iostream> 
using namespace std; 

int main() 
{ 
 	system("./meaning"); 
    return 0; 
}
So system is easy way,but also think about security if using system calls.
python001 likes this post
Reply
#5
(Nov-01-2020, 06:12 AM)Larz60+ Wrote: FYI: there are very reliable binary packages available for all python OS versions here: https://www.python.org/downloads/ it's not necessary to rebuild from scratch.

For Linux, all I found are "source tarball". I have to make/build by myself. Am I wrong?
Reply
#6
Well, I haven't used fedora for many years, but found the following, which applies to python 3.7, I suspect, but not sure, that same applies up through python 3.9.
https://fedoramagazine.org/python-3-7-no...in-fedora/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Is possible to run the python command to call python script on linux? cuten222 6 631 Jan-30-2024, 09:05 PM
Last Post: DeaD_EyE
  How to use a variable in linux command in python code? ilknurg 2 1,547 Mar-14-2022, 07:21 AM
Last Post: ndc85430
  Setup Portable Python on Windows for script starts with double clicks? pstein 0 1,778 Feb-18-2022, 01:29 PM
Last Post: pstein
  Python syntax in Linux St0rmcr0w 2 44,733 Jul-29-2021, 01:40 PM
Last Post: snippsat
  Login to NordVPN on Linux with python script AGreenPig 2 5,908 Feb-09-2021, 10:44 AM
Last Post: AGreenPig
  how to run linux command with multi pipes by python !! evilcode1 2 6,218 Jan-25-2021, 11:19 AM
Last Post: DeaD_EyE
  Portable installation of Python possible? pstein 2 3,003 Nov-15-2020, 12:14 PM
Last Post: snippsat
  Python in Linux environment on RPI kendias 22 10,906 Sep-05-2020, 03:04 AM
Last Post: K_Research
  How do I pick the right python in Linux env? MDRI 9 3,585 Jun-27-2020, 05:40 PM
Last Post: snippsat
  control a linux program with python Fifoux082 9 4,006 May-08-2020, 04:24 PM
Last Post: Fifoux082

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020