PyInstaller as of this writing, doesn't support Python 3. There is however this page on freezing your code or shipping:
Solution | Windows | Linux | OS X | Python 3 | License | One - file mode | Zipfile
import | Eggs | pkg_resources support
bbFreeze | yes | yes | yes | no | MIT | no | yes | yes | yes
py2exe | yes | no | no | no | MIT | yes | yes | no | no
pyInstaller | yes | yes | yes | no | GPL | yes | no | yes | no
cx_Freeze | yes | yes | yes | yes | PSF | no | yes | yes | no
Install pyinstaller first by -
pip install pyinstaller
Usage -
pyinstaller example.py
This will generate binary in in a subdirectory called build/
& the dependencies will be under dist/
in source folder of your script.
ls - lha build / example / example ls - lha dist / example /
Basically, you make a directory that contains directories for all your modules, and your program file, which should be named __main__.py
.
> ls
__main__.py lamprop /
>
ls lamprop /
__init__.py html.py latex.py parser.py text.py types.py
This is then wrapped up in a zip-file, and given a shebang-line for use on UNIX-like systems;
cd src;
zip - q.. / foo.zip __main__.py lamprop
/*.py
echo '#!/usr/bin/env python' >lamprop
cat foo.zip >>lamprop
chmod a+x lamprop
rm -f foo.zip
On Windows you can find the user base binary directory by running py -m site --user-site and replacing site-packages with Scripts. For example, this could return C:\Users\Username\AppData\Roaming\Python36\site-packages so you would need to set your PATH to include C:\Users\Username\AppData\Roaming\Python36\Scripts. You can set your user PATH permanently in the Control Panel. You may need to log out for the PATH changes to take effect.,On Linux and macOS you can find the user base binary directory by running python -m site --user-base and adding bin to the end. For example, this will typically print ~/.local (with ~ expanded to the absolute path to your home directory) so you’ll need to add ~/.local/bin to your PATH. You can set your PATH permanently by modifying ~/.profile.,Also, what if you can’t install packages into the global site-packages directory? For instance, on a shared host.,To install from other data sources (for example Amazon S3 storage) you can create a helper application that presents the data in a PEP 503 compliant index format, and use the --extra-index-url flag to direct pip to use that index.
python3--version
py--version
>>> python --version
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'python' is not defined
In[1]: import sys!{
sys.executable
}--version
Python 3.6 .3
python3 - m pip--version
py - m pip--version
Write, run, and debug a Python "Hello World" Application,Learn how to install packages by creating Python virtual environments,This tutorial introduces you to VS Code as a Python environment, primarily how to edit, run, and debug code through the following tasks:,For additional examples of creating and activating a virtual environment and installing packages, see the Django tutorial and the Flask tutorial.
Linux/macOS: open a Terminal Window and type the following command:
python3--version
Windows: open a command prompt and run the following command:
py - 3--version
Linux/macOS: open a Terminal Window and type the following command:
python3--version
Windows: open a command prompt and run the following command:
py - 3--version
Using a command prompt or terminal, create an empty folder called "hello", navigate into it, and open VS Code (code
) in that folder (.
) by entering the following commands:
mkdir hello
cd hello
code.
You can also work with variables in the Debug Console (If you don't see it, select Debug Console in the lower right area of VS Code, or select it from the ... menu.) Then try entering the following lines, one by one, at the > prompt at the bottom of the console:
msg msg.capitalize() msg.split()
Return to the Explorer view (the top-most icon on the left side, which shows files), create a new file called standardplot.py
, and paste in the following source code:
import matplotlib.pyplot as plt import numpy as np x = np.linspace(0, 20, 100) # Create a list of evenly - spaced numbers over the range plt.plot(x, np.sin(x)) # Plot the sine of each x point plt.show() # Display the plot
For Windows
py - 3 - m venv.venv .venv\ scripts\ activate
If the activate command generates the message "Activate.ps1 is not digitally signed. You cannot run this script on the current system.", then you need to temporarily change the PowerShell execution policy to allow scripts to run (see About Execution Policies in the PowerShell documentation):
Set - ExecutionPolicy - ExecutionPolicy RemoteSigned - Scope Process
For macOS/Linux
python3 - m venv.venv source.venv / bin / activate
Install the packages
# Don 't use with Anaconda distributions because they include matplotlib already. # macOS python3 - m pip install matplotlib # Windows(may require elevation) python - m pip install matplotlib # Linux(Debian) apt - get install python3 - tk python3 - m pip install matplotlib
01/24/2022
Open PowerShell and create an empty folder called "hello", navigate into this folder, and open it in VS Code:
mkdir hello
cd hello
code.
Open PowerShell (or Windows Command Prompt) and create an empty folder called "bounce". Navigate to this folder and create a file named "bounce.py". Open the folder in VS Code:
mkdir bounce
cd bounce
new - item bounce.py
code.
Using VS Code, enter the following Python code (or copy and paste it):
import sys, pygame
pygame.init()
size = width, height = 640, 480
dx = 1
dy = 1
x = 163
y = 120
black = (0, 0, 0)
white = (255, 255, 255)
screen = pygame.display.set_mode(size)
while 1:
for event in pygame.event.get():
if event.type == pygame.QUIT: sys.exit()
x += dx
y += dy
if x < 0 or x > width:
dx = -dx
if y < 0 or y > height:
dy = -dy
screen.fill(black)
pygame.draw.circle(screen, white, (x, y), 8)
pygame.display.flip()