running python script without installed libraries

  • Last Update :
  • Techknowledgy :

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 -


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

> ls lamprop /
   ls lamprop /

This is then wrapped up in a zip-file, and given a shebang-line for use on UNIX-like systems;

cd src;
zip - q.. / lamprop
echo '#!/usr/bin/env python' >lamprop
cat >>lamprop
chmod a+x lamprop
rm -f

Suggestion : 2

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.

>>> python --version
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
      NameError: name 'python' is not defined
In[1]: import sys!{
Python 3.6 .3
python3 - m pip--version
py - m pip--version

Suggestion : 3

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:


Windows: open a command prompt and run the following command:

py - 3--version

Linux/macOS: open a Terminal Window and type the following command:


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

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:


Return to the Explorer view (the top-most icon on the left side, which shows files), create a new file called, 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 # 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

Suggestion : 4


Open PowerShell and create an empty folder called "hello", navigate into this folder, and open it in VS Code:

mkdir hello
cd hello

Open PowerShell (or Windows Command Prompt) and create an empty folder called "bounce". Navigate to this folder and create a file named "". Open the folder in VS Code:

mkdir bounce
cd bounce
new - item

Using VS Code, enter the following Python code (or copy and paste it):

import sys, pygame


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), white, (x, y), 8)