Code that worked for months suddenly stopped working.
In a file in the same directory 'downloaders', I have an import 'import image_downloader'. Somehow, the import doesn´t work anymore. The file that imports it is in the same directory.
My PyCharm IDE shows no problems at all, no warning or anything. But when I run it, the ModuleNotFoundError happens:
ModuleNotFoundError: No module named 'image_downloader'.
I have looked at similar questions here, but they haven´t helped me so far. I am desperate, and would be thankful for tips on resolving this annoying issue.
I found the solution. Not sure why it doesn´t work anymore with the old import style.
But what made it work: using absolute imports. This means in this case, instead of import image_downloader, I used from downloaders import image_downloader, even when the importing file is also in the package image_downloader.
Related
I am having this error while I run the project:
from .miner import Miner
ImportError: attempted relative import with no known parent package
1--> init file, 2--> malicious miner.py which shoes the above-mentioned error.
As it is mentioned in the picture I have a module name miner, there is also init to make share the proper module import, I have double-checked the files but somehow this error is presenting. Can Someone please help me to solve this issue?
This is the init file:
from .miner import Miner
from .malicious_miner import MaliciousMiner
while importing it doesn't show any error but when I run the file
I strongly suggest you to use PyCharm. Creating and importing files from the IDE really helps a lot in this type of problems, because it's not only creating an init. I would like to help you further if using PyCharm won't solve the problem
I've been struggling for quite some time trying to import a module from a molder in a separate directory on my computer for a python project. Currently the code seems to work, but Pycharm is still giving me errors that the module cannot be found. Despite this, if I run the code it seems to do what is intended.
What I have is essentially this:
import sys
sys.path.append(r'D:\Progam\bin')
import foo
Where foo is a module found in D:\Progam\bin, and it's warning me that there is no module named foo. Considering how much issue I've for some reason had to get this working I'm hesitant to just ignore the warning if there's some underlying problem
Anyone have any idea what's happening here?
Because the file isn't in your path globally, your IDE isn't recognizing that it is then valid during execution. It would probably be a security issue if it were adding files to its path from potentially unknown code.
You could either add that directory to your path via CMD like so:
set PATH=%PATH%;C:\your\path\here\
Or just ignore the error.
EDIT: Ignore that, I'm being a sleep deprived dumbass. Take a look at:
how to manage sys.path globally in pycharm
(Thought this edit would be slightly more useful than me just deleting my answer)
I've encountered one peculiar issue I just can't understand.
I've been working on a code in PyCharm, using Python 3.6 (Windows 10) and I've imported few modules for that objective like so:
import requests
from bs4 import BeautifulSoup
import time
import lxml
For few days now I've been coding having no problems, I've run my code several times to test it and everything been going well until suddenly, without changing anything in the interpreter or any other setting, the modules seem to generate a lot of import errors such as:
ImportError: cannot import name 'BeautifulSoup'
AttributeError: module 'requests' has no attribute 'get'
This is so weird, suddenly I can't run my code and all my work is halted.
I've been looking up the internet and saw that usually this happens if you call one of your files in a same name as a module (for example, naming my file bs4.py), I'm afraid this is not the case here, I made sure my file is named in a unique name which doesn't exist anywhere on said libraries.
I couldn't find any other solution for this.
Can anyone help me figure this one out?
Still learning certain things about Python... I am having issues recognizing my Python script in my scripts dir. First, I checked to see that my path is set correctly:
import sys
for pythonPath in sys.path:
print pythonPath
And C:/Users/..../Documents/maya/2014-x64/scripts is listed, which is where I am placing swap.py
In Maya's script editor I am typing the following:
import swap
reload(swap)
swap.printSomething()
I get:
Error: AttributeError: file line 3: 'module' object has no attribute 'printSomething' #
If I take the same code and throw it into a package...
C:/Users/..../Documents/maya/2014-x64/scripts/swapPackage/swap.py
And then call this, it works...
import swapPackage.swap as swap
reload(swap)
swap.printSomething()
Why? I am totally confused. Mel scripts even run fine from this location as well. I just can't get a simple python script to import and run.
Also something I noticed. Even though I can get this script to run in a package, the package name must be totally different than the module name. I can't have a package named this:
C:/Users/..../Documents/maya/2014-x64/scripts/swap/swap.py
but I can have one where the package name is different:
C:/Users/..../Documents/maya/2014-x64/scripts/swapPackage/swap.py
Ok folks, I was able to solve this by executing a print of my file, only to find out that it was sourcing a totally different version someone copied elsewhere. ARGH. This solves both issues, and makes sense why changing the package name from the module worked.
import swap
reload(swap)
print swap.__file__
i've looked at other threads looking at the same problems and the solutions suggested there have not worked
whenever i try to execute this code i get this
import random
print random.randit(0,5)
AttributeError: 'module' object has no attribute 'randit'
to see if there was a file that was named random before it reaches the correct random.py i did
random.__file__
which gave me this readout
'/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/random.pyc'
I went to that folder and checked out random.py and confirmed that it has the function randit;
i've tried moving my code so that my working directory is in the python2.5/random.pyc directory and it still does not work.
i've tried moving the random.py from framework library into my working directory of my code and it is not working; i checked the random.file after doing so and it does not switch to the current working directory that contains a copy of the random.py from frameworks
furthermore, i have tried reinstalling python as well which did not change anything
this code was working before, but when I tried to run that line in a bigger set of code that wasn't exporting any files and is not named random, thats when I stopped being able to run the random.randit function even in a completely new .py file in a completely new working directory
lastly, i've tried importing the math module and that module works fine
does anyone have any suggestions for what else I can do to troubleshoot this?
Try this. I think your code had a typo it's randint not randit. Let me know if this helped you.
import random
print random.randint(0,5)