How do I make pyinstaller identify my custom imports? - python

I'm trying to create an exe out of a small Python Project. I have a main.py which imports packages from other subdirectories. After building the exe using pyinstaller when I run the executable I am facing import problems, its failing to identify the relative imports.
I tried modifying the .spec file but am unable to rectify the issue.
This is the current directory structure of my project
Link to project structure image
When I run the executable dist\cli\cli.exe it gives me this import error
Traceback (most recent call last):
File "cli.py", line 3, in <module>
from packages.__main__ import main
ImportError: No module named __main__
[5964] Failed to execute script cli

Related

How to solve the output problem with CodeRunner in vscode?

I have my own project with virtual environment. When I am trying to debug code everything executes flawlessly and I get the expected output, but when I am trying to run it with run code option from Code Runner extension I receive the error:
[Running] python -u "c:\Users\slikm\Pulpit\ytapi\yt_api.py" Traceback (most recent call last): File "c:\Users\slikm\Pulpit\ytapi\yt_api.py", line 2, in <module> from googleapiclient.discovery import build ModuleNotFoundError: No module named 'googleapiclient'
I have the library which the module is taken from installed on my venv. I read that the problem might be with the interpreter the extension uses, but I don't really know how to figure it out.

ModuleNotFoundError: No module named in Python

I keep getting this error in VS Code:
Traceback (most recent call last):
File "c:\Users\User Name\Documents\Productivity\Coding\Python\Udemy\Projects from course\MilestoneP2\app.py", line 1, in <module>
import MilestoneP2.utils.Operations_db as Db
ModuleNotFoundError: No module named 'MilestoneP2'
I have recently shifted from Pycharm to VS Code and I am trying to open some of those projects from pycharm in VS Code but there is the above error haunting me.
PS: I have my Python Interpreter in a different directory and not in the workspace folder. It's in D:\Python\venv Drive
Here is my code:
import MilestoneP2.utils.Operations_db as Db
Here is the file hierarchy.
Anyone Help?
Thank you
If you run the script within VSCode there is a Python version button on bottom-left.
When you click on it you can specify your Python or virtual environment path. It will also try to find them automatically from directories. Then you can run your scripts with the spesified environments.

Python, importing custom libraries from subdirectory, working in IDE, not in shell

For sake of organization, I've placed all my custom libraries into a subdirectory. When I run my script file in the spyder IDE, it imports everything as intended, and runs smoothly, but when I execute the script from shell, it fails to import. (I have created an __init__.py file in the modules/ directory).
Also, this is being run on Linux.
Here is my code:
import os
dirpath = os.path.dirname(__file__)
sys.path.append('{}/modules/'.format(dirpath))
#custom libraries in dirpath/modules/
import data_pull
import features
import create_listings
example = data_pull.mp(pool)
data = features.generate(example)
Shell output:
Traceback (most recent call last):
File "data_manager.py", line 15, in
import data_pull
ModuleNotFoundError: No module named 'data_pull'

No Module named twilio.rest

I have installed python 2.7.12 with PATH access and correctly installed twilio. However, when I try to execute a code I get this error message:
Traceback (most recent call last):
File "C:\Python27\textmessage.py", line 1, in <module>
from twilio.rest import TwilioRestClient
ImportError: No module named twilio.rest
Also, I want to know where we have to install Twilio, as I installed the Twilio library and placed it inside the Scripts folder.
You should not put modules into the Scripts folder.
To install twillio, see the documentation.
Check the path. I had the same problem when I put the file send_text.py in the folder called C:\Python27\Projects. I then copy the file and placed in in the folder C:\Python27 where the libs folder is right under it. The module ran. This was a test on my system.

"No module named 'osmium._osmium'" error when trying to use PyOsmium

I am trying to use PyOsmium but it will not import. python3 setup.py install appears to complete just fine but when I import osmium I get the error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/dylan/Downloads/osmium/osmium/__init__.py", line 1, in <module>
from ._osmium import *
ImportError: No module named 'osmium._osmium'
I have no idea what's causing this and it's my first time manually installing a C++ wrapper. I have the top-level PyOsmium and libosmium directories in the same directory. Is it trying to import the C++ files?
Any help would be much appreciated.
I had the same problem. The solution, as provided by one of the maintainers, is very easy:
Are you in the pyosmium root directory while trying the import? Change the directory to somewhere else and try again. In the root directory the local osmium source directory takes precedence over your freshly installed version.
Change to a different directory from the one you compiled in and it should work; it did for me.

Categories