ImportError: cannot import name Multipoint - python-3.x

I'm trying to import Multipoint from shapely.geometry like so:
from shapely.geometry import Multipoint
state = Multipoint(((36.977397, -102.985840),(37.004892, -109.050293)(31.805382, -109.006348),(31.861385, -103.095703))).convex_hull
point.within(polygon)
But I get the following error:
ImportError: cannot import name Multipoint
Anyone know what's causing this error?

Try
from shapely.geometry import MultiPoint
Make sure you are using a capital 'P' in the word MultiPoint. Docs

Related

ModuleNotFoundError: No module named 'keras.layers.preprocessing'

After writing this -
VERIFICATION_SCRIPT = os.path.join(paths['APIMODEL_PATH'], 'research', 'object_detection', 'builders', 'model_builder_tf2_test.py')
!python {VERIFICATION_SCRIPT}
I am getting this error-
from keras.layers.preprocessing import image_preprocessing as image_ops
ModuleNotFoundError: No module named 'keras.layers.preprocessing'
This error is because there is no api named keras.layers.preprocessing. The correct name of this api is tensorflow.keras.preprocessing and you can import image from this api not image_preprocessing
Try using:
from tensorflow.keras.preprocessing import image as image_ops
in place of (incorrect way)
from keras.layers.preprocessing import image_preprocessing as image_ops
Please check this link for more details.

Django unable to get models module

I am learning Django and not sure what is causing the error 'ModuleNotFoundError: No module named 'models''
even though the files are in the same folder
files are available here
File "/Users/mayanksharma/Library/Mobile Documents/com~apple~CloudDocs/for Stackoverflow/app-7-django/blogs/urls.py", line 1, in <module>
from . import views
File "/Users/mayanksharma/Library/Mobile Documents/com~apple~CloudDocs/for Stackoverflow/app-7-django/blogs/views.py", line 2, in <module>
from models import Post
ModuleNotFoundError: No module named 'models'
Do you mean by?
from .models import Post
Replace from . import views with:
import sys
sys.append('..')
import views
This was something to do with python reading path instead of from .models import Post or from . import views I gave from app.models import Post and that made it work

OpenMDAO and NSGA II

I found some interesting code in openmdao\drivers\tests\test_pyoptsparse_driver.py that seems to reference NSGA-II. I noticed that this is not implemented when I tried running the test code.
import sys
import copy
import unittest
sys.path.insert(0,r"[SOMEPATH Here]\GitHub\OpenMDAO")
from distutils.version import LooseVersion
import numpy as np
import openmdao.api as om
from openmdao.test_suite.components.paraboloid import Paraboloid
from openmdao.test_suite.components.expl_comp_array import TestExplCompArrayDense
from openmdao.test_suite.components.sellar import SellarDerivativesGrouped
# from openmdao.utils.assert_utils import assert_near_equal # NOTE: THIS FUNCTION ISN'T AVAILABLE IN THE PIP INSTALL
from openmdao.utils.general_utils import set_pyoptsparse_opt, run_driver
from openmdao.utils.testing_utils import use_tempdirs
from openmdao.utils.mpi import MPI
_, local_opt = set_pyoptsparse_opt('NSGA2')
if local_opt != 'NSGA2':
raise unittest.SkipTest("pyoptsparse is not providing NSGA2") # CODE BASICALLY FAILS HERE
Error that I am seeing:
"pyoptsparse is not providing NSGA2"
Can I add NSGA 2 if it's not available?
when that test was written, NSGA-II was a little difficult to compile with pyoptsparse. I think there are still some challenges with it, but it mostly works now. As of OpenMDAO V3.0 we're not using NSGA-II for anything internally. But if you get it to work, feel free to send a PR with an updated test!

invalid syntax for unknown reason

I'm doing some django stuffs using vs code and this error in the line 3 ("from") happend for no reason.
from django.urls import path
from * import views
urlpatterns = [path(" ",views,name="home")]
Your second import seems to be incorrect.
The syntax should be:
from <module> import <library / *>
In your case, it should be:
from views import *
That should be correct, as long as the views module do exist and can be found by python.
You cannot import like from *. Python expects a package name after from. If you are trying to import it from the relative path it might be something like
from . import views
Its a valid syntax error, and it did not happen for no-reason!

Import of an attribute of a python module fails

I have the following directory structure:
http://localhost:8888/notebooks/translation.ipynb
http://localhost:8888/edit/Fill_temp/prepare_test_data.py
In
prepare_test_data.py
I have a function:
def to_cap (EXP_FILE, SAMPLES_FILE: str= EXP_FILE + '.cap', cap_rate=0, by_token=False):
In the notebook
translation.ipynb
I do these imports:
%load_ext autoreload
%autoreload 2
import Fill_temp
import Fill_temp.prepare_test_data
then I run
Fill_temp.prepare_test_data.to_cap("en12.json.pres", "en12.cap.0")
and I get
AttributeError: module 'Fill_temp.prepare_test_data' has no attribute 'to_cap'
How come?
I explicitly imported both the Fill_temp package and the prepare_test_data module.
Do I need to import even the lowest level functions that are defined in the module?
EDIT:
I tried to import the low level function explicitly:
%load_ext autoreload
%autoreload 2
import Fill_temp
import Fill_temp.prepare_test_data
import Fill_temp.prepare_test_data.to_cap
but I get:
ModuleNotFoundError: No module named
'Fill_temp.prepare_test_data.to_cap';
'Fill_temp.prepare_test_data' is not a package
So what shall I do?
This is a bit bizarre. Basically, it turned out that there was a syntax error in that low level function.
But instead of saying it jupyter was saying that it doesn't see that function. Which is a really counter-intuitive error message.

Resources