ModuleNotFoundError: No module named 'libs.strings' - python

This is the error I am facing right, I google it a lot but solutions did not work, I am using python 3.7 in my django application.
Code:
from libs.strings import *
Error:
ModuleNotFoundError: No module named 'libs.strings'

As I have checked the libs module from pypi. The libs module doesn't seem to have strings. So doing pip install libs wont solve your problem.
Maybe libs could be a directory in your project you are trying to access. If so, then:
Check Proper path for libs folder.
In order to define libs as a single package, add empty __init__.py file in each folder; so the whole directory system act as a python module.

Related

How to resolve Python Module Not Found Error?

I am facing a problem in importing modules in python. I looked for a solution and found this. but this did not worked either.
My Directory is as follows
->MyScrapper --->MyScrapper ----->db_connection.py --->Video_Scrapper -----> video_scrapper.py --->Blogs_Scrapper -----> blogs_scrapper.py
I want to import db_connection.py in video_scrapper.py as well as blogs_scrapper.py. I have tried to import it as from MyScrapper.db_connection import DBConnection. It throws a ModuleNotFoundError: No Module named 'MyScrapper'. I have also tried using from db_connection import DBConnection and import DBConnection but none of them worked.
Please Help!!
When importing a module in python, it will search the module in this order:
build-in module
script in the current directory
PATHPYTHON
installation-dependent default
So, you need to add the MyScrapper module to the search path. If you use a virtual environment, you can add your project root directory into the PYTHONPATH, by modify the PYTHONPATH in the Scripts\activate.bat file, like this:
set PYTHONPATH=%VIRTUAL_ENV%\src;%PYTHONPATH%
I use the virtual environment, and my project struct is:
|--Include
|--Lib
|--Scripts
|--src
My source files are in the src directory.

cannot import from partially initialized module 'noise'

I have the current 'noise' package 2.2 in python3.8
It appears to have a circular import problem;
I do not believe I have any similarly named files in my own folders.
My code:
import noise
Result>
import noise
File "C:\Python\Python38\lib\site-packages\noise\__init__.py", line 12, in
from . import _perlin, _simplex
ImportError: cannot import name '_perlin' from partially initialized module 'noise' (most likely due to a circular import) (C:\Python\Python38\lib\site-packages\noise\__init__.py)
From a Github issue regarding this problem:
What's happening is that Python prefers to look for modules in relative paths before absolute paths. Since you can import noise from the repo directory, that means it's probably already in your python path(an absolute path).
Say this repository lives in foo/noise/ and now you are in foo/ if you go up a directory and try to run import noise. Python will see that the local directory noise/ as a module because it has an init.py file and try to import the directory instead of the module installed in your python path. Since this module requires the _noise and _simplex C extensions to be compiled, this wont work.
I'd recommend removing or renaming this repo directory from your project and use pip to install noise if you haven't already. (pip install noise)
If you really want to install from source and not install into your system, then, in the noise/ repository, run python setup.py build to build locally and grab dist/lib*/noise/ and put that directory into your project directory.
Alternatively use python setup.py install in the noise/ repository to install from source into your Python path.

How do I install/import module to python on mac

I haven't used python since my undergrad days so I'm incredibly rusty. I'm trying to install CERN's ROOT module. It's already installed on the mac terminal but I wish to access it in python too. I have it saved in site-packages which I have checked is the correct directory where all of my other accessible modules: numpy, scipy, matplotlib etc are housed.
Folder is called rootpy and includes the __init__.py file along with the ROOT.py and ROOT.pyc files, and other files, but when I try to import it under name rootpy or ROOT I receive the error:
ImportError: No module named rootpy
or,
ImportError: No module named ROOT
Does anybody know how to import the package?

cannot import fbconsole, fbconsole install?

I am trying to use fbconsole.
The website say
pip install fbconsole
But I dont have pip, so I use easy_install fbconsole and fbconsole is installed.
I check Python directory and there is fbconsole-0.3-py2.7.egg file.
I try to import fbconsole, but the error is
Internal Server Error
import_string() failed for 'myapp.views.index'. Possible reasons are: - missing __init__.py in a package; - package or module path not included in sys.path; - duplicated package or module name taking precedence in sys.path; - missing module, class, function or variable; Debugged import: - 'myapp' found in 'D:\\PythonProj\\LLL\\myapp\\__init__.pyc'. - 'myapp.views' not found. Original exception: ImportError: No module named fbconsole
UPDATE 1: My Project structure is
which is quite different with your explanation because I am using KAY framework.
I follow your explanation but still fail to import the package.
you need to put the fbconsole module into your GAE project to make it work.
installing it via pip or easy install does make it available for your local python but not for the GAE project.
When I pip install fbconsole I don't get an .egg file, but an .egg-info file, which is only metadata, along with the project files fbconsole.py and fbconsole.pyc. It appears a source package is the only uploaded format on PyPI, so it appears your issue is you need to copy the fbconsole.py file (and optoinally fbconsole.pyc, although it will rebuild this file on first access) to your packages directory if you're using my path_fixer.py script, or to the root of your project if not.
Here's more info about the differences between .egg and .egg-info files.
There are two basic formats currently implemented for Python eggs:
.egg format: a directory or zipfile containing the project's code and resources, along with an EGG-INFO subdirectory that
contains the project's metadata
.egg-info format: a file or directory placed adjacent to the project's code and resources, that directly contains the project's
metadata.
http://svn.python.org/projects/sandbox/trunk/setuptools/doc/formats.txt

Python library path

I have a python file "testHTTPAuth.py" which uses module deliciousapi and is kept in "deliciousapi.py".
I have kept the files like
testHTTPAuth.py
lib
deliciousapi.py
But when i run: "python testHTTPAuth.py" it's giving error
import deliciousapi
ImportError: No module named deliciousapi
How can handle these python libraries? Because later I have put the code together with libraries as Google app. So I can't keep the library in normal library path.
You need to add the 'lib' directory to your path - otherwise, Python can't find your source. The following (included in a module such as testHTTPAuth.py) will do that:
sys.path.append(os.path.join(os.path.dirname(__file__), 'lib')
Ned's suggestion of changing your imports may work, but if anything in the lib directory imports submodules with absolute paths (most large modules do this), then it'll break.
If you add an empty __init__.py to your lib directory, you can change your import statement to:
from lib import deliciousapi

Categories

Resources