0

I created a Python executable file using PyInstaller in a Conda environment called citygrows_demo.

I ran conda install nltk to install this package into the environment, and when I run conda list I can see the nltk package is installed.

I then created the executable file called common_fields_script.exe using the command

pyinstaller "C:\Users\lakna\OneDrive\Desktop\CityGrows\common_fields\common_fields_script.py" --onefile --icon="C:\Users\lakna\OneDrive\Desktop\CityGrows\common_fields\touchscreen_book_bookmark_ebook_icon_191190.ico"

However, when I run this executable file it says that there is no module named nltk.

Why is this the case?

merv
  • 67,214
  • 13
  • 180
  • 245
Nathan123
  • 763
  • 5
  • 18
  • How are you creating the executable? – osint_alex Aug 04 '21 at 20:52
  • @osint_alex I ran this to create the executable `pyinstaller "C:\Users\lakna\OneDrive\Desktop\CityGrows\common_fields\common_fields_script.py" --onefile --icon="C:\Users\lakna\OneDrive\Desktop\CityGrows\common_fields\touchscreen_book_bookmark_ebook_icon_191190.ico"` – Nathan123 Aug 04 '21 at 20:57
  • Is `pyinstaller` installed in the environment? – merv Aug 06 '21 at 04:19

2 Answers2

0

As you are using the virtual environment, then activate the environment using conda activate citygrows_demo, and then install the conda install nltk.

But the question is python is itself an executable and the python code is interpreted. what is the executable common_fields_script.exe.

If you have written a python script in common_fields_script, save it as common_fields_script.py and run it using the python.exe which is created inside the virtual environment, in the terminal, something similar to below:

(citygrows_demo) C:/<path_where_your_scirpt_is>> python common_fields_script.py
Sup
  • 191
  • 5
0

I think that pyinstaller is missing a module when creating the executable.

To fix this, run pyi-makespec "C:\Users\lakna\OneDrive\Desktop\CityGrows\common_fields\common_fields_script.py" and then edit which modules it imports in the spec file.

There's a good example on how to do that here. In short you need to manually add the absolute path to the nltk package that conda installed in the datas section of the .spec file that the above command creates.

Once you've done that, run pyinstaller common_fields_spec.spec "C:\Users\lakna\OneDrive\Desktop\CityGrows\common_fields\common_fields_script.py"

osint_alex
  • 952
  • 3
  • 16