Cannot import name 'GeoText' from the geotext Python package - python

I have installed the geotext module from pip.
However this line:
from geotext import GeoText
produces this error:
ImportError: cannot import name 'GeoText'
The module structure is as follows:
where there is no sub directory but directly the geotext python file containing the GeoText class:
The correct syntax of "from module import Class" is used in the __init__.py file too.
from geotext import GeoText
Could anyone help me interpret as to why the error could be generated in such a scenario where there seems to be no circular imports?

The import statement from the init file needs to be removed. This corrects the circular import scenario.

I had the same problem.
Installing geotext like so fixed it for me:
python3 -m pip install geotext

Related

How to have Python package not require import package.package

tl;dr - My python package requires import package.package instead of working with just import package. How do I get it to work with the latter?
I am trying to set up my first python package and am running into some issues with the import part of the process.
My python package file setup looks like this on my computer:
my-package
- build
- dist
- package
- package.egg-info
- LICENSE
- README.md
- Setup.py
Inside package is the following:
__init__.py
package.py
__init__.py reads name = 'package', and package.py contains all of the content of the package.
EDIT: I have attempted using various different versions of __init__.py, including adding import package, import package.package, or import package.package as package below the line name = 'package', but all of resulted in the same issue.
Using the Packaging Python Projects tutorial, I've been able to get my package upload to TestPyPi, but when I install the package to my computer, none of the functions/methods are available, and when I run "import package" and do help(package), I get the following:
Help on package package:
NAME
package
PACKAGE CONTENTS
package
DATA
name = 'package'
FILE
url/to/package
When I run import package.package and help(package), I can access the methods/functions, and get the expected help text for the package's content.
My question is, how to I configure the package file on my computer in such a way that once it is upload to TestPyPi and then downloaded, import package works, instead of needing to run import package.package?
When you write import package, you can access names in package/__init__.py as package.foo.
So, inside __init__.py, if you import all the necessary functions/variables/etc from package.py, those names will be visible to clients that just import package.
So, if you have this in package/__init__.py:
from .package import (foo, bar, baz)
Then in your other code you can do this:
from package import foo
And you dont have to worry about from package.package import foo.

Importing from one module to another

I have two modules in the same directory:
PDSC2.py and db_layer.py
I want to import a class named DBLayer from db_layer.py so I write:
from db_layer.py import DBLayer
But I get an error:
ModuleNotFoundError: No module named 'db_layer'
Does somebdy have an idea what i'm doing wrong?
first of all assume that this python files in the same directory and then remove extension from your code.
from db_layer import DBLayer
or:
from db_layer import *
Is the directory in a place where python searches for modules, python path? Do you have a __init__.py in the directory (it can be blank)?
You need to paste the program file db_layer.py in the \Python\Python36-32\Scripts directory
, then use from db_layer import DBLayer or from db_layer.py import DBLayer to call the desired class in the python program .
Actually sometimes changing the directory of the called module to \Python\Python36-32\Scripts solves these types of problems easily.
This is the solution that worked for me:
import sys
sys.path.append("C:\\Users\\carmel.han\\AppData\\Roaming\\QGIS\\QGIS3\\profiles\\default\\python\\plugins/filterparcel")
from db_layer import DBLayer

Python load_source import not found

I am not a proficient Python coder, hence this might be a basic question:
In my main python code, I load a python code file using (dynamically)
import imp
model = imp.load_source('name','c:/modeldir/modelfile.py')
modelfile.py does an import on the top:
from MyLib import MyLib
MyLib.py is in the same folder as modelfile.py
I get:
ImportError: No module named 'MyLib'
I have also tried:
import os
os.chdir('c:/modeldir')
just before the imp.load_source, did not help.
EDIT:
I am using Python 3.5.2
I've added an empty __init__.py file in 'c:/modeldir'
How to solve this?
The following made it work
sys.path.append('c:/modeldir')
This adds the folder to the python import path and then MyLib can be found

Tensorflow translate.py import error: No module named translate

I'm trying to run Tensorflow's translate.py from a python console rather than through bazel -build, but I get an error at these two lines:
from tensorflow.models.rnn.translate import data_utils
from tensorflow.models.rnn.translate import seq2seq_model
ImportError: No module named translate
I've checked the folder to see that the "init.py" file is there, but python seems to think there is no such module as translate.
How can i fix this?
The best way to do this is to navigate to folder containing the translate module and running it. You can also download the translate module to any other place and run it. However, don't forget to change the above lines to:
from translate import data_utils
from translate import seq2seq_model
I resolved this issue by removing all the from tensorflow.models.rnn.translate statements, leaving just
import data_utils
import seq2seq_model
in translate.py and
import data_utils
in seq2seq_model.py.

Python ImportError: cannot import name datafunc [PyML]

I have installed PyML package in order to use some machine learning algorithms, and according to the tutorial, my installation is successful.
I try to run a python script which includes the following line to import modules from PyML
from PyML import datafunc,svm,assess,modelSelection,ker
However I get the error message above saying
File <stdin>, line 1, in <module> ImportError: cannot import name
datafunc
cannot import name datafunc`. From terminal I check every module by saying
from PyML import datafunc,
from PyML import svm,
from PyML import ker
I only get error message for datafunc. The PyML library is under the site-packages folder of Python 2.7.
I check this question here Python error: ImportError: cannot import name Akismet, but I could't see how it will help my problem.
Do you have any idea why Python imports some modules but does not import this one?
In PyML-0.7.13.3, the datafunc module exists in PyML/containers directory.
So it seems that you can import the module as follows:
from PyML.containers import datafunc
Howerver, it raises an error beacuse the datafunc module uses
undefined classes BaseVectorDataSet and SparseDataSet.
Thus you need to modify the source of PyML
in order to use datafunc module.
First, prepend the following two lines to PyML/containers/datafunc.py
and re-install the PyML library.
from PyML.containers.baseDatasets import BaseVectorDataSet
from PyML.containers.vectorDatasets import SparseDataSet
Then you can import the modules as follows:
from PyML import svm, modelSelection, ker
from from PyML.containers import datafunc
from from PyML.evaluators import assess
BTW, I recommend that you use more documented and tested machine learning library, such as scikit-learn.

Categories