"ModuleNotFoundError: No module named 'kivymd'" in .spec file

Question:

I already did pip install kivymd in my Python project. I also had the kivymd directory in my project.
I’m working with a Mac.
I created a spec file called "coinsnack4.spec" including the code below:

from kivymd import hooks_path as kivymd_hooks_path

However, when I try to package my python project with the spec file with the command:

pyinstaller -y --clean --windowed coinsnack4.spec

I got the error below:

  File "coinsnack4.spec", line 3, in <module>
    from kivymd import hooks_path as kivymd_hooks_path
ModuleNotFoundError: No module named 'kivymd'

I really don’t know why this happens because I already pip install kivymd. I don’t know what to do next and I would appreciate if anyone could help me with this error.

Thank you very much!

Asked By: Upchanges

||

Answers:

Why are you facing this issue?

The reason behind this is the concept of virtual environments in python. Each virtual environment is independent of the other. You can use different virtual environments, activate and deactivate them as per your project’s requirements.

I would suggest you go through this doc once Python venv

As when you do a `pip install <SOME_PACKAGE> from your local terminal, it installs the package from into the default python environment and from the terminal itself (not pycharm terminal) if you try to execute the python program it will work fine but as soon as you switch to pycharm or any other IDE, it has it’s own python environment set and that environment is unaware of what happened in the other python environment. So you need to install the pip package here also, in order to execute the same python program.

Solution:-

The first thing I would suggest is to install the package in the virtual environment that the pycharm is using. For that click on the Terminal icon the below bar of your pycharm window. then do run the below command :-

python3 -m pip install kivymd

If this doesn’t work, try configuring the python environment in pycharm.

Below is how you can change or update your python interpreter in pycharm: –

Setting an existing Python interpreter

At any time, you can switch your Python interpreter either using the Python Interpreter selector or in the Project Settings/Preferences.

1

2
3

4

Creating a new Python interpreter

To add a new interpreter to the current project:
5

If you have a conda environment, follow the below steps: –

6

Or if you want to setup a new virtual environment, do as below: –

7
8
9

Answered By: Alok Raj

I think you installed pyinstaller not in project’s virtualenv, just:

pip install pyinstaller

then problem will be fixed.

Answered By: 5t2m
Categories: questions Tags: , , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.