BlueHawk77
BlueHawk77

Reputation: 105

pyinstaller - Excluding Modules

First of all let me tell that I'm quite new to Python.

I have a very simple python file I want to convert to exe.

As the file is very simple, I don't want to add any modules to it at the start then add necessary ones one by one, testing if they are really necessary or not.

For this purpose, as suggested at some post here in stackoverflow, I'm creating and activating a new virtual environment at my Visual Studio Code IDE via these commands at terminal;

python -m virtualenv testenv
testenv\Scripts\activate

Then I check to be sure that there are no modules installed via pip freeze and yes there are no modules installed.

now at this virtual environment I enter;

pyinstaller test.py --clean

the installer creates the files and folders necessary, but although no modules are installed at this virtual environment I see a lot of modules in created in dist folder which are in fact installed at main python environment.

What am I missing here ?

Also is there a keyword / option / spec file option for excluding all the modules installed at the current environment and include only the ones selected ? (PS I am aware of --exclude-module option and excludes=[] option at spec file but don't want to input all the installed module names one by one.)

Any help is greatly appreciated.

Upvotes: 1

Views: 1456

Answers (1)

Alexander
Alexander

Reputation: 17291

Once you have activated you virtual environment make sure you pip install pyinstaller. Otherwise you will be using the global pyinstaller which has access to all global modules.

By installing pyinstaller into your virtual env, when you run the command it will only have access to the modules inside the virtual env.

If you still continue to see modules after that, then those are the modules pyinstaller deemed necessary to run the executable.

Upvotes: 2

Related Questions