Python 3.x import class module not found error - python

Trying to import a class into my Python code from another .py file I've written and included in the same sub-directory, however I'm receiving the error:
ModuleNotFoundError: No module named 'main.S_DES_Functions'; 'main' is not a package
Please find below images of the layout of my Python project.
I'm hoping this is just a really silly mistake I'm making, so if anyone can please advise what I'm doing wrong that'd be great :)

Thanks for the suggestions, I tried them however was still receiving the same error. But I managed to find a work around, similar to what is listed in this other Stack Overflow question - Unresolved reference issue in PyCharm
I basically made a new directory for my classes and set it as the directory as a "Source" for the project, which then allowed me to import it and use the classes without any issues.

Related

Why does VS studio give me an error when I try to import a function, class, etc

The problem is that, when I try to import a certain class from a .py archive that is in the same package it gives me an error. I have tried using from .something import function, from something import function and both ways end in error.
So your question is kinda vague but ive had a similar issue from what I understand in sublime text
to solve this make sure you have the correct python interpreter on visual studio

Can't find mb_protocol module for python

I've been trying to install PythonToolkit on Linux, but I've encountered some problems. Whenever I try to run the PTK.pyw I get the error: No module named 'mb_protocol'.
Now, I've googled the name but I haven't been able to find a module named mb_protocol. I did however find another stackoverflow post that mentioned the same module.
The creator of the post told me that he had found the module, but unfortunatly he can't remember where.
So if anybody knows how I should go about installing this module, please do tell.

Using a function from a built-in module in your own module - Python

I'm new with Python and new on Stackoverflow, so please let me know if this question should be posted somewhere else or you need any other info :). But I hope someone can help me out with what seems to be a rather simple mistake...
I'm working with Python in Jupyter Notebook and am trying to create my own module with some selfmade functions/loops that I often use. However, when I try to some of the functions from my module, I get an error related to the import of the built-in module that is used in my own module.
The way I created my own module was by:
creating different blocks of code in a notebook and downloading it
as 'Functions.py' file.
saving this Functions.py file in the folder that i'm currently working in (with another notebook file)
in my current notebook file (where i'm doing my analysis), I import my module with 'import Functions'.
So far, the import of my own module seems to work. However, some of my self-made functions use functions from built-in modules. E.g. my plot_lines() function uses math.ceil() somewhere in the code. Therefore, I imported 'math' in my analysis notebook as well. But when I try to run the function plot_lines() in my notebook, I get the error "NameError: name 'math' is not defined".
I tried to solve this error by adding the code 'import math' to the function in my module as well, but this did not resolve the issue.
So my question is: how can I use functions from built-in Python modules in my own modules?
Thanks so much in advance for any help!
If anyone encounters the same issue:
add 'import math' to your own module.
Make sure that you actually reload your adjusted module, e.g. by restarting your kernell!

No module named 'utils'

I am new to the world of python. I am trying to learn first order logic from https://github.com/aimacode/aima-python/blob/master/logic.ipynb
I just follow the same steps as mentioned but I get the following error.
ModuleNotFoundError: No module named 'utils'
I use Jupyter notebook for the testing purpose. I can see there are questions related to this error. But still I could not solve it.
Thanks for any input.
You need to clone the whole Github repo, not only download (or copy from) the Notebook.
See utils.py is a separate file.
https://github.com/aimacode/aima-python/blob/master/utils.py
Also refer to Installation Guide

Python ImportError (Cannot import name Variables)

I have done some research on this question and nothing seems to fix it, I suspect I may be accidentally circularly importing somewhere, but this one has stumped me.
This package is a Python IRC Service framework. The issue occurs when dynamically loading a module (via imp.load_source()), and the new module tries to import something from the src folder (Variables.py). It fails with "Cannot import name Variables", yet, it imports another module from the same directory without complaint.
Here is the specific error:
**ERROR: ModLoad(): Unable to load module
/home/sam/workspace/Affinity/bin/../modules/ircd_affinity.py:
cannot import name Variables
**
This is the full file for modules/ircd_affinity.py: ircd_affinity.py, and src/Variables.py: Variables.py
If it helps. browse the entire repository... this (https://github.com/miniCruzer/Affinity/blob/master/src/Affinity.py) module (starting at line 123) loads modules.
I would appreciate if all responses were kept relevant to the specific issue at hand. Yes, it may be tempting to suggest other things I'm doing wrong or otherwise throughout the entire package - I am welcome to suggestions: please e-mail them to me.
Show the full traceback. Look through it for evidence of (attempted) circular import.
Run Python with the -v option ... what does that tell you?
Look at the contents of sys.path and sys.modules just before the error happens.
"**ERROR: ModLoad(): Unable to ..." doesn't look line a Python-raised error. Is that in your code? If so, dig deeper; why is it raised?

Categories

Resources