I'm learning Python from scratch.,

Virutal environment

Here’s a condensed version of the development environment process.

A virtual environment makes sure that if you have a 5 year old project, it’s libraries do not clash with a new project you just made. But you have more copies of the libraries on your disk, because there are copies for each project. But it makes the whole process easier if you want to compile to an EXE file

  1. Install Python. This includes checking your path is set up correctly to the Python EXE and it’s libraries.
  2. Make a project directory for all Python projects. Call it “Pyprojects”.
  3. Under “Pyprojects” make a new directory for one project, call it “Project1”. So you end with with directories like “Pyprojects/Project1”.
  4. Go to directory “Project1”. cd project1.
  5. Make your environment while inside the project1 dir: There are different tools to do this. I use virtualenv. Type: virtualenv .venv.
  6. Before installing libraries, activate the environment. .venv\scripts\activate. Your command prompt should now be prefixed with “.venv” which is the name of the environment we made above.
  7. Now install python libraries with pip, they will be installed under the .venv directory. Ex: pip install pandas installs the pandas library which is used for reading and writing spreadsheets, CSV files, etc. You will often need another library to go with this like xlswriter. So just ask if you get an error when you run the program.

Compile Python to EXE

Most popular packages to do this are:

  1. Pyinstaller. It’s for Python 3.8+ only. PyInstaller Manual — PyInstaller 6.10.0 documentation
  2. cs_freeze. It supports Python 3.8 to 3.12 right now. Python v3.13 is still in release candidate status but will be released in October I think. cx_Freeze 7.2.2 documentation
  3. Py2app. py2app - Create standalone Mac OS X applications with Python — py2app 0.28.8 documentation For Mac only.

And if so , then would user not need to install .py , etc.?

Correct they would need the EXE file only, they would not have to install Python, that’s the point of an EXE file. All libraries are in the EXE file but for Pyinstaller you need to specify an option for that. Pyinstaller, which I’ve used, does not compile in all libraries by default. I think you use the --onefile switch.

c- would the .exe the run on MACOS & Linux ?

For windows, yes. For mac, see Py2app above. For Linux, see quote below. From the first page of Pyinstaller docs:

PyInstaller is tested against Windows, MacOS X, and Linux. However, it is not a cross-compiler; to make a Windows app you run PyInstaller on Windows, and to make a Linux app you run it on Linux, etc. x PyInstaller has been used successfully with AIX, Solaris, FreeBSD and OpenBSD but testing against them is not part of our continuous integration tests,

Tip 1: Key point: Watch out for this error:

pip install selenium
Requirement already satisfied: selenium in c:\users\MYUSER\ ...

This means the package is already installed in that environment.

Tip 2: Also the name you use for the import statement like import dotenv does not always match the name you use to install it via pip. For this example you must use pip install python-dotenv.

Handy links, Please write this down

  1. Where you get Python to install and Python docs. https://python.org
  2. Where you get libraries and library documentation. https://pypi.org
  3. Indently free Python tutorials. https://www.youtube.com/results?search_query=indently+python+tutorial