Create executable file for windows for python script through Anaconda command prompt
1. Save the python coding in the folder where you want to create an exe file.
2. Open the Anaconda Navigator. Open the Command Prompt app from it.

3. Execute the following command to install the pyinstaller.
pip install pyinstaller
Example:
(base) C:\Users\adminuser>pip install pyinstaller
Collecting pyinstaller
Downloading pyinstaller-4.5.1-py3-none-win_amd64.whl (1.9 MB)
|████████████████████████████████| 1.9 MB 6.8 MB/s
Requirement already satisfied: pywin32-ctypes>=0.2.0 in c:\users\adminuser\anaconda3\lib\site-packages (from pyinstaller) (0.2.0)
Collecting altgraph
Downloading altgraph-0.17.2-py2.py3-none-any.whl (21 kB)
Requirement already satisfied: setuptools in c:\users\adminuser\anaconda3\lib\site-packages (from pyinstaller) (52.0.0.post20210125)
Collecting pyinstaller-hooks-contrib>=2020.6
Downloading pyinstaller_hooks_contrib-2021.3-py2.py3-none-any.whl (200 kB)
|████████████████████████████████| 200 kB ...
Collecting pefile>=2017.8.1
Downloading pefile-2021.9.3.tar.gz (72 kB)
|████████████████████████████████| 72 kB 238 kB/s
Requirement already satisfied: future in c:\users\adminuser\anaconda3\lib\site-packages (from pefile>=2017.8.1->pyinstaller) (0.18.2)
Building wheels for collected packages: pefile
Building wheel for pefile (setup.py) ... done
Created wheel for pefile: filename=pefile-2021.9.3-py3-none-any.whl size=68832 sha256=eb9e0a1f4fc514e589dfc10da0a130711f6a9aab1d146b332d084f2d00d5af59
Stored in directory: c:\users\adminuser\appdata\local\pip\cache\wheels\ee\a0\e1\ff2dafe5ae846f536acf0a4cc4a8b8d4ccb3044ab87f3ef174
Successfully built pefile
Installing collected packages: pyinstaller-hooks-contrib, pefile, altgraph, pyinstaller
Successfully installed altgraph-0.17.2 pefile-2021.9.3 pyinstaller-4.5.1 pyinstaller-hooks-contrib-2021.3
4. Go to the folder where python script is saved. Python script save with .py extention.
5. Execute the following command to create an exe in that folder with Python script.
pyinstaller --onefile pythonScript.py
Example:
(base) C:\D>cd Datapumputility
(base) C:\D\Datapumputility>dir
Volume in drive C is Windows
Volume Serial Number is 58A9-BBEC
Directory of C:\D\Datapumputility
09/29/2021 10:45 AM <DIR> .
09/29/2021 10:45 AM <DIR> ..
09/29/2021 10:45 AM 32,040 datapumpforschema.py
1 File(s) 32,040 bytes
2 Dir(s) 217,529,942,016 bytes free
(base) C:\D\Datapumputility>pyinstaller --onefile datapumpforschema.py
2662 INFO: PyInstaller: 4.5.1
2662 INFO: Python: 3.8.8 (conda)
2663 INFO: Platform: Windows-10-10.0.18362-SP0
2667 INFO: wrote C:\D\Datapumputility\datapumpforschema.spec
2676 INFO: UPX is not available.
2695 INFO: Extending PYTHONPATH with paths
['C:\\D\\Datapumputility', 'C:\\D\\Datapumputility']
6149 INFO: checking Analysis
6152 INFO: Building Analysis because Analysis-00.toc is non existent
6152 INFO: Initializing module dependency graph...
6162 INFO: Caching module graph hooks...
6290 INFO: Analyzing base_library.zip ...
15212 INFO: Processing pre-find module path hook distutils from 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
15217 INFO: distutils: retargeting to non-venv dir 'c:\\users\\adminuser\\anaconda3\\lib'
22616 INFO: Caching module dependency graph...
23010 INFO: running Analysis Analysis-00.toc
23040 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by c:\users\adminuser\anaconda3\python.exe
23476 INFO: Analyzing C:\D\Datapumputility\datapumpforschema.py
23520 INFO: Processing module hooks...
23520 INFO: Loading module hook 'hook-cx_Oracle.py' from 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\_pyinstaller_hooks_contrib\\hooks\\stdhooks'...
23526 INFO: Loading module hook 'hook-difflib.py' from 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
23532 INFO: Loading module hook 'hook-distutils.py' from 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
23538 INFO: Loading module hook 'hook-distutils.util.py' from 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
23544 INFO: Loading module hook 'hook-encodings.py' from 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
24030 INFO: Loading module hook 'hook-heapq.py' from 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
24036 INFO: Loading module hook 'hook-lib2to3.py' from 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
24378 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
24385 INFO: Loading module hook 'hook-pickle.py' from 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
24391 INFO: Loading module hook 'hook-sysconfig.py' from 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
24396 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
24401 INFO: Loading module hook 'hook-xml.py' from 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
24656 INFO: Loading module hook 'hook-_tkinter.py' from 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks'...
25531 INFO: checking Tree
25533 INFO: Building Tree because Tree-00.toc is non existent
25534 INFO: Building Tree Tree-00.toc
27232 INFO: checking Tree
27234 INFO: Building Tree because Tree-01.toc is non existent
27234 INFO: Building Tree Tree-01.toc
27867 INFO: checking Tree
27869 INFO: Building Tree because Tree-02.toc is non existent
27869 INFO: Building Tree Tree-02.toc
27919 INFO: Looking for ctypes DLLs
28021 INFO: Analyzing run-time hooks ...
28026 INFO: Including run-time hook 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
28038 INFO: Including run-time hook 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
28047 INFO: Including run-time hook 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_win32api.py'
28075 INFO: Including run-time hook 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
28082 INFO: Including run-time hook 'c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth__tkinter.py'
28097 INFO: Looking for dynamic libraries
28467 INFO: Looking for eggs
28467 INFO: Using Python library c:\users\adminuser\anaconda3\python38.dll
28468 INFO: Found binding redirects:
[]
28477 INFO: Warnings written to C:\D\Datapumputility\build\datapumpforschema\warn-datapumpforschema.txt
28540 INFO: Graph cross-reference written to C:\D\Datapumputility\build\datapumpforschema\xref-datapumpforschema.html
28606 INFO: checking PYZ
28610 INFO: Building PYZ because PYZ-00.toc is non existent
28611 INFO: Building PYZ (ZlibArchive) C:\D\Datapumputility\build\datapumpforschema\PYZ-00.pyz
29461 INFO: Building PYZ (ZlibArchive) C:\D\Datapumputility\build\datapumpforschema\PYZ-00.pyz completed successfully.
29474 INFO: checking PKG
29477 INFO: Building PKG because PKG-00.toc is non existent
29477 INFO: Building PKG (CArchive) PKG-00.pkg
32451 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
45918 INFO: Bootloader c:\users\adminuser\anaconda3\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
45918 INFO: checking EXE
45921 INFO: Building EXE because EXE-00.toc is non existent
45921 INFO: Building EXE from EXE-00.toc
45931 INFO: Copying icons from ['c:\\users\\adminuser\\anaconda3\\lib\\site-packages\\PyInstaller\\bootloader\\images\\icon-console.ico']
46027 INFO: Writing RT_GROUP_ICON 0 resource with 104 bytes
46027 INFO: Writing RT_ICON 1 resource with 3752 bytes
46028 INFO: Writing RT_ICON 2 resource with 2216 bytes
46031 INFO: Writing RT_ICON 3 resource with 1384 bytes
46031 INFO: Writing RT_ICON 4 resource with 37019 bytes
46033 INFO: Writing RT_ICON 5 resource with 9640 bytes
46034 INFO: Writing RT_ICON 6 resource with 4264 bytes
46035 INFO: Writing RT_ICON 7 resource with 1128 bytes
46047 INFO: Updating manifest in C:\D\Datapumputility\build\datapumpforschema\run.exe.gzmdod9_
46048 INFO: Updating resource type 24 name 1 language 0
46058 INFO: Appending archive to EXE C:\D\Datapumputility\dist\datapumpforschema.exe
52901 INFO: Building EXE from EXE-00.toc completed successfully.
6. Exe for python command is created in dist folder. Following is the location :
C:\D\Datapumputility\dist\datapumpforschema.exe
If in my code I create a json file, by default, my file will be saved inside the script folder, where will be this file saved after I execute the ‘.exe’ file created with your help? Thank you!
LikeLike