Procedure to exe python file from Ubunts environment construction

Introduction

I've never used Ubunts, and I got into Hyper-V from the beginning. From there, I got various information as to whether there are not many opportunities to exeize python in the world, but I will summarize it because I was able to exe.


environment windows10 64bit ubunts 20.04 python 3.7.7 pip 20.2.4 pyenv version 2020.11.15 pyinstaller 4.0


What is __Hyper-v __ One of the virtualization technologies provided by windows for free. Functions that are installed as standard in windows8 and windows server. It can be used by turning on the function from the server manager. Click here for details __ What is Hyper-V? __

-Run Ubuntu on Hyper-V on Windows 10 -I think that there is no problem in building ubunts if you look at this article and build it. You will need to set the'network adapter'to the new virtual switch later in the network settings in the virtual machine settings created by Hyper-V Manager.

Get the latest ubuntu package information

sudo apt update

Updated ubuntu package information

sudo apt upgrade

Various installations to use pyenv

sudo apt install -y build-essential # c ++ compiler sudo apt install -y libffi-dev sudo apt install -y libssl-dev # openssl sudo apt install -y zlib1g-dev sudo apt install -y liblzma-dev sudo apt install -y libbz2-dev libreadline-dev libsqlite3-dev # bz2, readline, sqlite3 sudo apt install -y git

Install pyenv package

git clone https://github.com/pyenv/pyenv.git ~/.pyenv

.bashrc update

echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
source ~/.bashrc

python installation

pyenv install 3.7.7

I used 3.8.5 by default, so I want to use 3.7.7 this time by default.

echo "3.7.7" > .python-version

Installation of pipenv

pip install pipenv

WARNING: You are using pip version 19.2.3, however version 20.2.4 is available. You should consider upgrading via the 'pip install --upgrade pip' command.

I think this guy will come out

pip install --upgrade pip

Initial setting of pipenv

 pipenv install

When developing with Python, a tool that easily and automatically manages packages for each project and builds a virtual environment. You can use pip to install packages and virtualenv (venv) to build virtual environments, but pipenv supports them so that they can be handled more easily.

Using /usr/bin/python3.8 to create virtualenv ・ ・ ・

×Failed creating virtual enviroment In my case I got the above error. It seems that the Python version is different

 pipenv --python 3.7

You have now specified the Python version to use.

activate

 pipenv shell

I put it in a virtual environment

Install if package required

 pipenv install argparse
 pipenv install argparse==1.4.*

Make sure it's in the Pipfile

 cat Pipfile

Introduction of pyinstaller

 pip install pyinstaller

Introduced pyinstaller with pipenv

 pipenv install pyinstaller

Move to the directory where the file you want to exe exists,

exe execution

 LD_LIBRARY_PATH=/home/namae/.pyenv/bin/pyenv pyinstaller test.py

This caused an error.

 OSError: Python library not found: libpython3.7m.so.1.0 libpython3.7mu.so.1.0 libpython3.7.so.1.0 libpython3.7m.so
This would mean your Python installation doesn't come with proper library files.
This usually happens by missing development package, or unsuitable build parameters of Python installation.
* On Debian/Ubuntu, you would need to install Python development packages
  * apt-get install python3-dev
  * apt-get install python-dev
* If you're building Python by yourself, please rebuild your Python with `--enable-shared` (or, `--enable-framework` on Darwin)

** Occurs when pyenv install is done without setting the --enable-shared option in the environment variable PYTHON_CONFIGURE_OPTS. ** **

 LD_LIBRARY_PATH=/home/namae/.pyenv/versions/3.7.7 pyenv install
 LD_LIBRARY_PATH=/home/namae/.pyenv/versions/3.7.7 pyinstaller test.py --onefile
 
 Building EXE from EXE-00.toc completes successfully.

The exe is ready! !!

Operation check

 cd dist
 ./test
hello

It's running, OK!

There is a big problem with the folder The file I want to exe is so big (although it was about 12MB) It's done.


__ Referenced article __

--__ Environment construction with Debian + anyenv (pyenv) + pipenv __ --__ Notes on making it executable with Pyinstaller __

--__ Talk about installing pyenv on ubuntu 20.04 [Updated on 2020/07/18] __

Recommended Posts

Procedure to exe python file from Ubunts environment construction
From Python environment construction to virtual environment construction with anaconda
Anaconda3 python environment construction procedure
Python development environment construction 2020 [From Python installation to poetry introduction]
From Ubuntu 20.04 introduction to environment construction
Python project environment construction procedure (for windows)
Python environment construction
How to convert Python to an exe file
Environment construction (python)
[Python] Road to snake charmer (1) Environment construction
Procedure from environment construction to operation test of testinfra, a server environment test tool made by Python
python environment construction
Python --Environment construction
Environment construction procedure: Ubuntu + Apache2 + Python + Pyramid
python environment construction
Procedure from AWS CDK (Python) development to AWS resource construction * For beginners of development
Collecting information from Twitter with Python (Environment construction)
VS Code + Azure Functions + Python environment construction procedure
From Kivy environment construction to displaying Hello World
Python explosive environment construction starting from zero (Mac)
Import Excel file from Python (register to DB)
From 0 to Django development environment construction to basic operation
python windows environment construction
Changes from Python 3.0 to Python 3.5
homebrew python environment construction
Mac environment construction Python
Python environment construction @ Win7
Environment construction procedure to operate chrome without installing python on Windows (using selenium)
From setting up Raspberry Pi to installing Python environment
From Kafka to KSQL --Easy environment construction with docker
Google App Engine / Python development environment construction procedure (late 2014)
[Python] Change standard input from keyboard to text file
Python script to create a JSON file from a CSV file
Python + Anaconda + Pycharm environment construction
Post from Python to Slack
Cheating from PHP to Python
Python environment construction (Windows10 + Emacs)
Anaconda updated from 4.2.0 to 4.3.0 (python3.5 updated to python3.6)
CI environment construction ~ Python edition ~
Python environment construction For Mac
Python3 environment construction (for beginners)
Python environment construction and TensorFlow
Switch from python2.7 to python3.6 (centos7)
Connect to sqlite from python
Python environment construction under Windows7 environment
[MEMO] [Development environment construction] Python
Environment construction of python2 & 3 (OSX)
OpenJTalk on Windows10 (Speak Japanese with Python from environment construction)
Summary from building Python 3.4. * From source to building a scientific computing environment
From environment construction to deployment for flask + Heroku with Docker
Python environment construction procedure memo using Docker on Windows10 Home
[Python Kivy] How to create an exe file with pyinstaller
(Translation) Native connection from Python to Hadoop file system (HDFS)
Raspberry Pi + python + IoT device, environment construction procedure to start image processing and machine learning
Call Matlab from Python to optimize
Environment construction of python and opencv
Execute Python script from batch file
Python environment construction memo on Windows 10
Get started with Python! ~ ① Environment construction ~
I tried to convert a Python file to EXE (Recursion error supported)
How to rebuild python environment from pyenv on Mac environment (El Capitan)