pyinstaller no predefined compiler for raspberry pi - python

I want to convert myscript.py to a exexutable file. i am using raspberry pi(raspbian) and python 2.7.
I am issuing the following command
sudo pip install PyInstaller
sudo pyinstaller myscript.py
after some processing it provides an error
Fatal error: PyInstaller does not include a pre-compiled bootloader for your
platform. See <http://pythonhosted.org/PyInstaller/#building-the-bootloader>
for more details and instructions how to build the bootloader.
i go online to build compiler but could not understand the process.
how could i solve this problem?

Full Tutorial
After many hours of searching, I got this working. The answer is straightforward, but it is spread across multiple StackExchange answers and GitHub Issues. I put it all together in this tutorial, so I save some hours for the next poor soul.
Key Takeaways
pip ships PyInstaller with the incorrect architectures. You need to build it yourself for ARM (Raspberry Pi).
Step by Step
1. Build the bootloader
git clone https://github.com/pyinstaller/pyinstaller
# Alternatively download the zip from https://github.com/pyinstaller/pyinstaller/releases
cd pyinstaller/bootloader
python ./waf distclean all # or python3
cd ../PyInstaller/bootloader/
ls
Here you should see Linux-32bit-arm and inside of it run and run_d
2. Check the bootloader
file Linux-32bit-arm/run
run: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=a01c65d74d7d8b483800154dcdd4a5d2aad95d5b, stripped
If you see the above, you are good so far. However, if you see something like ELF 32-bit LSB executable, Intel 80386, that is wrong.
3. Copy the bootloader
If you installed PyInstaller with pip inside a venv, then do this
# Replace ${CLONED_PYINSTALLER_PATH} with the path where you git cloned above
# Replace ${PATH_TO_YOUR_PROJECT} with the path to your project (where you have the venv)
cp -r ${CLONED_PYINSTALLER_PATH}/PyInstaller/bootloader/Linux-32bit-arm ${PATH_TO_YOUR_PROJECT}/venv/lib/python3.5/site-packages/PyInstaller/bootloader/
If you installed with apt-get, then do this
# !!! Replace python3.5 with your version
cp -r ${CLONED_PYINSTALLER_PATH}/PyInstaller/bootloader/Linux-32bit-arm /usr/local/lib/python3.5/dist-packages/PyInstaller/bootloader
Debugging
Issue
SystemError: objcopy Failure: objcopy: Unable to recognise the format of the input file `$FILE`
Check
`file dist/$FILE`
If it does not say ELF 32-bit LSB executable, ARM [...], but instead says Intel or x86, the PyInstaller tries to use the incorrect bootloader. If you executed all steps above, try renaming the Linux-32bit-arm to just Linux-32bit. That seems to have worked for this user
Issue
gcc not found
Solution
sudo apt-get install build-essential

Suspect path for the compilation of bootloader is wrong for your platform
may do this as mentioned in the forum here
cd /usr/local/lib/python2.7/dist-packages/PyInstaller/bootloader
sudo mv Linux-32bit Linux-32bit-arm
For RPI you need to get bootloader... You may cloned pyinstaller v3.1.1 into your rpi
Same thing, change the directory name for your arm platform after you have build the pyinstaller
cd /path/to/pyinstaller/PyInstaller/bootloader
cp -R Linux-32bit Linux-32bit-arm

For RPI, please clone the pyinstaller source code first and then follow my instructions.
Switch to pyinstaller/ bootloader subfolder.
Make the bootloader for your OS using the following command:
python3.5 ./waf distclean all
Make the Linux-32bit-arm sub-folder in /usr/local/lib/python3.5/dist-package/PyInstaller/bootloader
Copy the run and run_d to Linux-32bit-arm:
cp pyinstaller/bootloader/build/debug/run_d /usr/local/lib/python3.5/dist-package/PyInstaller/bootloader/Linux-32bit-arm/
cp pyinstaller/bootloader/build/release/run /usr/local/lib/python3.5/dist-package/PyInstaller/bootloader/Linux-32bit-arm/

I was able to install and create executables, on a Raspberry Pi running Raspbian (stretch 9.4), by running setup.py. Python version installed is 3.5.3.
git clone https://github.com/pyinstaller/pyinstaller
Inside pyinstaller source folder, run sudo python3 setup.py install
After, just execute pyinstaller <source>.py.

Related

YouCompleteMe: compile problem ycm core library not detected. VIM. Linux MInt

The ycmd server SHUT DOWN (restart with ':YcmRestartServer'). YCM core library not detected; you need to compile YCM before using it.
I tried to compile ycm file using:
https://github.com/todaygood/go_repo/issues/5
Cannot run Python script using sudo
https://vimawesome.com/plugin/youcompleteme#linux-64-bit
and 2 more sources which include same info
but my problem starts when i try to run
python3 install.py
in terminal
Error:This script should not be run with sudo.
I have virtualenv, i have cmake, i tried to ran it in my env, i tried using different commands using pip, pip3, python, python3, sudo + <--(,,,,). Of course i tried to do it using root.
YouCompleteMe build example with a clean Ubuntu 20.04.3, installed/updated 10 days ago
sudo apt install build-essential cmake vim-nox \
python3-dev golang openjdk-11-jdk rust-all npm
## in /home/[name]/tmp/
git clone https://github.com/ycm-core/YouCompleteMe.git
cd YouCompleteMe/
git submodule update --init --recursive
./install.py --all
Generating ycmd build configuration...OK
Compiling ycmd target: ycm_core...OK
Building regex module...OK
Building watchdog module...OK
Installing Omnisharp for C# support...OK
Building gopls for go completion...OK
Setting up Tern for JavaScript completion...OK
Installing rust-analyzer for Rust support...OK
Installing jdt.ls for Java support...OK
Setting up TSserver for TypeScript completion...OK
Setting up Clangd completer...OK
(No issues with other OS´s either.)

"ModuleNotFoundError: No module named 'pysqlcipher3'" error while using Python 3.7 on windows 10

I am trying to decrypt one database file using Python 3.7. To decrypt it, I have to use pysqlcipher3 version for python 3.7. To install it, I have tried by using both commands:
pip3 install pysqlcipher3
and
pip install pysqlcipher3
and both the commands have showed successful installation of the pysqlcipher package. However, when I try to import pysqlcipher3 in my Python project by using this line:
from pysqlcipher3 import dbapi2 as sqlite
it displays this error:
ModuleNotFoundError: No module named 'pysqlcipher3
I have checked various GitHub projects, but none of them provide a clear working solution. The Python packages website says to install libsqlcipher in your OS but this time the issue is same, no documentation and link regarding for the installation of libsqlcipher for Windows 10. Can anyone provide me with proper installation steps, or any document, or any video tutorial, regarding the same? Or is there some issue with the import statement?
You need to install de library libsqlcipher-dev from your repository manager, for example:
sudo apt install libsqlcipher-dev
I don't normally post answers, but this worked for me on Ubuntu:
$ git clone https://github.com/coleifer/sqlcipher3
$ cd sqlcipher3
$ python setup.py build # Build against the system libsqlcipher
$ sudo python setup.py install
$ cd ..
then enter a python prompt and try:
from sqlcipher3 import dbapi2 as sqlcipher
Check if you have multiple pip installations by using
where pip
Also, check the interpreter being used in your project. Make sure it matches the python interpreter corresponding to the pip installation where the module was installed.
You might have to install libsqlcipher from source.
From https://github.com/sqlcipher/sqlcipher
Using MSVC
On Windows, all applicable build products can be compiled with MSVC.
First open the command prompt window associated with the desired
compiler version (e.g. "Developer Command Prompt for VS2013"). Next,
use NMAKE with the provided "Makefile.msc" to build one of the
supported targets.
For example:
mkdir bld
cd bld
nmake /f Makefile.msc TOP=..\sqlite
nmake /f Makefile.msc sqlite3.c TOP=..\sqlite
nmake /f Makefile.msc sqlite3.dll TOP=..\sqlite
nmake /f Makefile.msc sqlite3.exe TOP=..\sqlite
nmake /f Makefile.msc test TOP=..\sqlite
There are several build options that can be set via the NMAKE command
line. For example, to build for WinRT, simply add "FOR_WINRT=1"
argument to the "sqlite3.dll" command line above. When debugging into
the SQLite code, adding the "DEBUG=1" argument to one of the above
command lines is recommended.
SQLite does not require Tcl to run, but a Tcl installation is required
by the makefiles (including those for MSVC). SQLite contains a lot of
generated code and Tcl is used to do much of that code generation.
go checkout where your pip from by using pip -V, it outputs the pip path to you.
Check if this path is in the venv you want. If not, the package was installed in a wrong path.
Check if you have multiple python versions installed on your Operating System. Also if you are using a virtual environment you should activate that before installing any packages.
You'll need to install sqlcipher and the python library pysqlcipher3 with something like:
brew install sqlcipher
pip3 install pysqlcipher3 --user

Idlex 1.13 : Unable to located "idlexlib"

I really like IDLE because it's simple and intuitive, not to mention it is lightweight, but one turnoff is its lack of Line Numbers which is very important (for me).
I installed Python 3.6.0 for all users and then installed IdleX (python setup.py install), both as Admin. The setup went smoothly and the console displayed all processes just fine. However, when I tried to run idlex, an error showed:
Unable to located "idlexlib".
Make sure it is located in the same directory as "idlexlib" or run setup.py
to install IdleX.
python setup.py install --user
I tried uninstalling IDLE then installed it for single user, reboot then run again but the problem is still the same.
I tried upgrading to Python 3.6.1 but with no luck. I also tried copying LineNumbers.py to idlelib then edited configextensions.def but still no luck.
This should be a textbook setup (or so I thought) but I can't get it to work.
P.S.: Using Windows 10, 64-bit
Prerequisites
This solution works on Ubuntu 20.04.2 LTS,
using
python3
idle3
python3-setuptools
idlex-1.18.zip
The solution to the issue comes in the form of installing idlex, but there's more to it than that, so I've written the whole process.
Update Repo & Install dependencies
sudo apt update
sudo apt install -y idle3 python3-setuptools
Download IDLEx extension package
sudo wget http://sourceforge.net/projects/idlex/files/idlex-1.18.zip -P ~/
Unzip & make idlex hidden
cd ~/
unzip idlex-1.18
mv idlex-1.18 .idlex-1.18
Remove extra directories
rm -rf ~/idlex-1.18 ~/idlex-1.18.zip
Install idlex
cd ~/.idlex-1.18
sudo python3 setup.py install
Ensure Idlex runs
cd ~/.idlex-1.18
python3 idlex.py
Exit the program and proceed to next step.
Create Desktop Shortcut
Setup desktop shortcut for easy access
nano ~/Desktop/idlex.desktop
Paste into the text file:
python3 ~/.idlex-1.18/idlex.py
Press Ctrl+X and type "Y" and enter to save file to desktop.
Make idlex.desktop executable
In terminal, or
sudo chmod +x ~/Desktop/idlex.desktop
Through gnome
Right-click idlex.desktop on your desktop > select "Properties":
Go to Permissions tab
Check the box, "Allow executing file as program"

compiling .py into windows AND mac executables on Ubuntu

I have been trying for hours to figure out how to do this going through pyinstaller's docs, but I haven't had any luck.
I have a single .py file, and I need that made into a .exe file executable in windows 7, and a .app (or what ever works) executable in OS X Lion. The problem is that when ever I use
python pyinstaller.py my_code.py
it compiles into a linux executable.
Pyinstaller doesn't build executables for cross-platform targets, only for the platform on which Pyinstaller is run "natively". However, WINE allows running the native Windows Pyinstaller under Linux, so it can be used to build Python scripts developed on Linux into native Windows .exe executables using only the single Linux host - no separate Windows host necessary. These instructions don't target Mac.
I'm using Ubuntu 15.10 on a 64bit Pentium-type.
$ uname -op
x86_64 GNU/Linux
$ grep DISTRIB_DESCRIPTION /etc/lsb-release
DISTRIB_DESCRIPTION="Ubuntu 15.10"
Ensure Python is installed.
$ apt-get install python2.7
[installed OK]
$ python --version
Python 2.7.10
(Upgrade and) use the Python package manager to install and
possibly upgrade Pyinstaller on Linux. Running pip without superuser
privileges might fail.
$ sudo -H pip install --upgrade pip
[upgraded OK]
$ sudo -H pip install PyInstaller
[installed OK]
$ sudo -H pip install --upgrade pyinstaller
[installed OK]
$ pyinstaller --version
3.0
You can install Python/Pyinstaller, install/configure WINE and write
Python code in any order (though running code requires Python is
installed). Use the Python package manager to install Python
packages pendent to your Python project.
$ pip install package1 [package2, ...]
[packages installed OK]
Test packaging the executable targeting Linux.
$ cd python-project
$ pyinstaller --onefile python-project.py
[built OK]
$ dist/python-project
[ran OK]
If it doesn't build or run OK, try building it as --onedir , the
Pyinstaller default, which doesn't include pendent files in the
single executable. That shouldn't build/run any differently than the
onefile version, but it can be easier to debug the onedir which
should then build OK as onefile too.
Ensure WINE is installed and configure it to use your selected
target Windows version (eg. Windows 7):
$ wine --version
wine-1.7.50
$ winecfg
[GUI: Applications tab > Windows Version: Windows 7]
Use WINE to install the Windows Python, pywin32 (Windows GUI
extensions); match their versions. You should probably go to each
installer's download page for the right versions and mirrors rather
than these current direct download links. Note that running WINE
dumps a lot of WINE bug notifications to the console; these are
practically all negligible in this procedure.
$ mkdir -p /opt/windows $ pushd /opt/windows
$ wget https://www.python.org/ftp/python/2.7.10/python-2.7.10.amd64.msi
$ wget http://iweb.dl.sourceforge.net/project/pywin32/pywin32/Build%20219/pywin32-219.win-amd64-py2.7.exe
$ wine msiexec -i python-2.7.10.amd64.msi $ wine msiexec -i pywin32-219.win-amd64-py2.7.exe
$ popd
I had problems with the Python 2.7.10 MSI wizard failing to "Next"
after selecting the install directory, so I cancelled it there and
ran it again adding the -qn option that suppresses the GUI. It
complained a little but it completed the installation. If you need
to find Windows Python in your Linux filesystem it's by default
installed in your Linux user's default WINE "C:" directory in your
home directory, ie. ~/.wine/drive_c/Python27 .
$ wine C:/Python27/python --version Python 2.7.10
$ find ~/.wine/drive_c -name python.exe ~/.wine/drive_c/Python27/python.exe
Upgrade Windows pip and install Pyinstaller using WINE Python/pip.
$ wine C:/Python27/Scripts/pip.exe install --upgrade pip
[upgraded OK]
$ wine C:/Python27/Scripts/pip.exe --version
pip 7.1.2 from C:\Python27\lib\site-packages (python 2.7)
$ wine C:/Python27/Scripts/pip.exe install pyinstaller
[installed OK]
$ wine c:/Python27/python.exe C:/Python27/Scripts/pyinstaller-script.py --version
3.0
Install your project's pendent packages with Windows pip
$ wine C:/Python27/Scripts/pip.exe install xlwt
[installed OK]
Now your Windows (WINE) Python environment is configured
equivalently to your Linux native environment. Running Windows
Pyinstaller under WINE generates a native Windows .exe executable.
Use the Windows Python script version of Windows Pyinstaller to
maintain parity with your tested OK Linux Pyinstaller procedure,
against your python project in your Linux filesystem (it doesn't
need to be copied to the WINE Windows filesystem). Keeping the
Windows build and dist directories separate from the tested OK
Linux one can help debugging the packaging procedure.
$ wine c:/Python27/python.exe C:/Python27/Scripts/pyinstaller-script.py --onefile --workpath=./win-wrk --distpath=/opt/windows python-project.py
[packaged OK]
$ ls -F /opt/windows/python-project.exe
python-project.exe*
$ wine /opt/windows/python-project.exe
[Windows app runs OK]
From the pyinstaller FAQ:
Can I package Windows binaries while running under Linux?
No, this is not supported. Please
use ​Wine for this, PyInstaller runs fine in Wine. You may also want
to have a look at ​this thread in the mailinglist. In version 1.4 we
had build in some support for this, but it showed to work only half.
It would require some Windows system on another partition and would
only work for pure Python programs. As soon as you want a decent GUI
(gtk, qt, wx), you would need to install Windows libraries anyhow. So
it's much easier to just use Wine.
In other words, you cannot simply run a command in Linux to build a Windows executable (or a Mac executable for that matter) like you are trying to do. The workaround they have provided for Windows (and only for Windows) is to install Wine.
Wine is a program that allows windows programs to run on Linux. It creates an environment that replicates a windows environment. The idea is that you would install Python (using a Windows Python installer), as well as any other libraries that you need (such as pyinstaller), into this environment. Then, still in that environment, you run the python pyinstaller.
I haven't done all of this, but the mailing list thread mentioned in the FAQ would be a good start. Here is an example that they use:
PYDIR="c:/Python27"
PYTHON="wine $PYDIR/python.exe"
WINPWD=$(winepath -w $(pwd))
cd pyinstaller
$PYTHON Configure.py
$PYTHON Makespec.py -p $WINPWD $WINPWD/diceroller.py
$PYTHON Build.py diceroller/diceroller.spec
It looks like this uses the old "Configure.py", "Makespec.py" and "Build.py", whereas nowadays the "pyinstaller.py" script tries to do all of this for you.

Unable to install Python without sudo access

I extracted, configured and used make for the installation package in my server.
However, I could not use make install. I get the error
[~/wepapps/python/Python-2.6.1]# make install
/usr/bin/install -c python /usr/local/bin/python2.6
/usr/bin/install: cannot create regular file `/usr/local/bin/python2.6': Permission denied
make: *** [altbininstall] Error 1
I run the folder with
chmod +x Python-2.6.1
I get still the same error.
How can I run make install without sudo access?
How can I install to a path under my home directory?
mkdir /home/masi/.local
cd Python-2.6.1
make clean
./configure --prefix=/home/masi/.local
make
make install
Then run using:
/home/masi/.local/bin/python
Similarly if you have scripts (eg. CGI) that require your own user version of Python you have to tell them explicitly:
#!/home/masi/.local/bin/python
instead of using the default system Python which “#!/usr/bin/env python” will choose.
You can alter your PATH setting to make just typing “python” from the console run that version, but it won't help for web apps being run under a different user.
If you compile something that links to Python (eg. mod_wsgi) you have to tell it where to find your Python or it will use the system one instead. This is often done something like:
./configure --prefix=/home/masi/.local --with-python=/home/masi/.local
For other setup.py-based extensions like MySQLdb you simply have to run the setup.py script with the correct version of Python:
/home/masi/.local/bin/python setup.py install
As of year 2020, pyenv is the best choice for installing Python without sudo permission, supposing the system has necessary build dependencies.
# Install pyenv
$ curl https://pyenv.run | bash
# Follow the instruction to modify ~/.bashrc
# Install the latest Python from source code
$ pyenv install 3.8.3
# Check installed Python versions
$ pyenv versions
# Switch Python version
$ pyenv global 3.8.3
# Check where Python is actually installed
$ pyenv prefix
/home/admin/.pyenv/versions/3.8.3
# Check the current Python version
$ python -V
Python 3.8.3
Extending bobince answer, there is an issue if you don't have the readline development package installed in your system, and you don't have root access.
When Python is compiled without readline, your arrow keys won't work in the interpreter. However, you can install the readline standalone package as follows: Adding Readline Functionality Without Recompiling Python
On the other hand, if you prefer to compile python using a local installation of readline, here's how.
Before doing as bobince was telling, compile and install readline. These are the steps to do so:
wget ftp://ftp.cwru.edu/pub/bash/readline-6.2.tar.gz
tar -zxvf readline-6.2.tar.gz
cd readline-6.2
./configure --with-prefix=$HOME/.local
make
make install
Then, add this line to your .bash_profile script:
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/.local/lib
Last, but not least, execute the following command
export LDFLAGS="-L$HOME/.local"
I hope this helps someone!
You can't; not to /usr, anyway. Only superusers can write to those directories. Try installing Python to a path under your home directory instead.

Categories