I want to know how I can use the pypy interpreter with a python file and then convert it to an exe file (python 3.x)
Asked
Active
Viewed 632 times
0
-
It seems not yet possible here: https://stackoverflow.com/questions/22025366/pypy-and-pyinstaller – M. Zhang Jul 05 '21 at 02:30
2 Answers
0
Here is an example of setup.py for a package simplepipreqs
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import io
import os
import sys
from shutil import rmtree
from setuptools import find_packages, setup, Command
# Package meta-data.
NAME = 'simplepipreqs'
DESCRIPTION = 'Generate requirements.txt for .py and .ipynb files.'
URL = 'https://github.com/Atharva-Gundawar/simplepipreqs'
EMAIL = 'atharva.n.gundawar@gmail.com'
AUTHOR = 'Atharva Gundawar'
REQUIRES_PYTHON = '>=3.6.0'
VERSION = '0.0.4'
REQUIRED = [
"pathlib","yarg","requests","argparse"
]
here = os.path.abspath(os.path.dirname(__file__))
try:
with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = '\n' + f.read()
except FileNotFoundError:
long_description = DESCRIPTION
# Load the package's __version__.py module as a dictionary.
setup(
name=NAME,
version=VERSION,
description=DESCRIPTION,
long_description=long_description,
long_description_content_type='text/markdown',
author=AUTHOR,
author_email=EMAIL,
python_requires=REQUIRES_PYTHON,
url=URL,
packages=[
'simplepipreqs',
],
package_dir={'simplepipreqs':
'simplepipreqs'},
entry_points ={
'console_scripts': [
'simplepipreqs = simplepipreqs.simplepipreqs:main'
]
},
include_package_data=True,
install_requires=REQUIRED,
keywords = 'Requirments Requirments.txt Requirment.txt python Ipython ipynb py',
zip_safe = False,
license='MIT',
classifiers=[
# Trove classifiers
# Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: Implementation :: CPython',
'Programming Language :: Python :: Implementation :: PyPy',
"Operating System :: OS Independent",
]
)
Notice how in entry_points
I used console_scripts
When you run python setup.py install
or you install it from pypi like pip install simplepipreqs
you can use simplepipreqs
command in your terminal/cmd or use the simplepipreqs.exe

Atharva Gundawar
- 475
- 3
- 10
0
There are various tools to do this, depending on what you want to achieve. From the simple to the impossible:
- @arthava-gundawar 's example will create an python package that you can upload to pypi.org, and other users will install python, then install your package, then be able to run it
- Tools like cx_Freeze, pyinstaller and others of this genre take your code, analyze it for dependencies and put the whole thing into an executable zip file. This gets tricky when you need to add various runtime libraries like QT or NumPy. Since your code is in a zip file, it is considered pretty easy to extract the source code. The advantage is you can distribute a single file that will work anywhere the executable will run. Usually this is limited to exactly the same operating system
- Tools like Nuitka and Cython take your python code and transpile it to C, making it difficult to reverse engineer and sometimes speeding it up. They do not supply means to package the resulting binary code into a form for easy distribution.
- There is no tool I am aware of that can convert arbitrary python code into a single executable like a go package. If you can sponsor such work you may be able to get a custom solution.

mattip
- 2,360
- 1
- 13
- 13