name 'TextPath' is not defined - python

I've tried running a program which imports the Pandapower library, and I get the Error:
NameError: name 'TextPath' is not defined
I installed Pandapower via pip install normally, and it works good, but it seems to have Problems with "pandapower.plotting.collections" and the class "class CustomTextPath(TextPath):"
Minimal Code:
import pandapower as pp
import pandapower.plotting as plot
TracebacK:
Traceback (most recent call last): File "-\Test.py", line 2, in <module> import pandapower.plotting as plot File "-\Python\Python310\lib\site-packages\pandapower\plotting\__init__.py", line 1, in <module> from pandapower.plotting.collections import * File "-\Python\Python310\lib\site-packages\pandapower\plotting\collections.py", line 36, in <module> class CustomTextPath(TextPath): NameError: name 'TextPath' is not defined

This is a bug in pandapower. They depend on having matplotlib installed. The code catches its absence with a try/except but still tries to use the elements it would have imported. So, do a pip install matplotlib and you should be good.

Related

How can I import functions from other folders in Python project?

I cannot import the functions from other packages in my Python project.
As suggested, I added
sys.path.append(os.path.abspath('../ExportExcel'))
from ExportExcel.export_excel import export_excel
at the beginning of the clip_finder.py.
I also put
sys.path.append(os.path.dirname(__file__)
inside the export_excel.py.
Inside ExportExcel.init.py I put
from .export_excel import export_excel
However I still get this error:
C:\Main\SupportScripts\ClipFinder>python clip_finder.py -h
Traceback (most recent call last):
File "C:\Main\SupportScripts\ClipFinder\clip_finder.py", line 12, in <module>
from ExportExcel.export_excel import export_excel
ModuleNotFoundError: No module named 'ExportExcel'
How can I make it work?

Datatable installation from github failing to find the version

I have uninstalled and re-installed the latest version of datatable from the repo
16:42:49/seirdc2.March8.in $sudo pip3 install 'datatable==0.10.1'
Successfully installed datatable-0.10.1
Let's see the version:
import datatable as dt
print(f'datatable version={dt.__version__}')
Um oops !
Traceback (most recent call last):
File "/git/corona/python/pointr/experiments/python/datatable.py", line 18, in <module>
import datatable as dt
File "/git/corona/python/pointr/experiments/python/datatable.py", line 19, in <module>
print(f'datatable version={dt.__version__}')
AttributeError: module 'datatable' has no attribute '__version__'
But why?
Note: I have seen other strangeness with this package: e.g. not finding Frame - though not consistently.
It appears that the problem has nothing to do with datatable. Look at the traceback:
Traceback (most recent call last):
File "/git/corona/python/pointr/experiments/python/datatable.py", line 18, in <module>
import datatable as dt
File "/git/corona/python/pointr/experiments/python/datatable.py", line 19, in <module>
print(f'datatable version={dt.__version__}')
AttributeError: module 'datatable' has no attribute '__version__'
Doesn't it strike you as suspicious that you have line 18 "calling" line 19? I mean, how could it be? Here's how:
When you name your script datatable.py and then do import datatable, then instead of importing the actual module from site-packages, it imports the "module" datatable.py instead. Basically, the file imports itself. And the way python manages imports, is that it creates a "stub" module in the sys.modules first (in order to prevent infinite recursions during imports). In your case, the module tries to import itself, so the stub module is fetched instead -- and then when you try to print its __version__ variable, turns out it doesn't exist.
You can verify this by printing dt.__file__ instead, which should show the location of the file that is being imported.
Needless to say, all this is not specific to datatable in any way; for example if you created a file numpy.py and then tried to import numpy, you'd run into same problems.

Python 'cannot import name 'TestCase'' When importing unittest

Whenever I attempt:
import unittest
I get the following error:
Traceback (most recent call last):
File "wackyTesting.py", line 1, in <module>
import unittest
File "C:\.....\Python\Python36\lib\unittest\__init__.py", line 59, in <module>
from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
ImportError: cannot import name 'TestCase'
This happens regardless of where the code is run, there is nothing in the root that could be causing a conflict. I have tried re-installing unittest but it didn't help. It was working perfectly until just recently. Any ideas?
Welp, I just uninstalled python completely and reinstalled. Nothing quite like turning it off and on again. That seems to have done it, maybe there's a more elegant solution but this will have to do for now.

Error while importing localization

I downloaded the localization package in Anaconda. But when I try to import it I get the following error:
Traceback (most recent call last): File "<pyshell#0>", line 1, in <module> import localization File "~\Python\Python36-32\lib\site-packages\localization\__init__.py", line 1, in <module>
from geoProject import *
ModuleNotFoundError: No module named 'geoProject'
I do not know what to do, can someone please help me out?
"geoProject", must be your project name, not the name of the module you are trying to input.
Try:
from your module import *
or just
import yourmodule
It works if your module is in current directory. Unless you should write the full path to your module

ImportError: cannot import name pynestkernel

So I spend last night trying to install nest (and pynest) to use with PyNN, and I am currently stuck. When I try to import nest I get:
>>> import nest
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nest/__init__.py", line 52, in <module>
from . import pynestkernel as _kernel
ImportError: cannot import name pynestkernel
However, when I make the make installcheck it passes all the pynest tests.
I am using OS x Yosemite, and I did a new install of python 2.7.9 using macport.
Tried:
easy_install python-nest
Now I am getting a new error.
Getting:
>>> import pyNN.nest as sim
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
import pyNN.nest as sim
File "/Library/Python/2.7/site-packages/pyNN/nest/__init__.py", line 13, in <module>
from pyNN.nest import simulator
File "/Library/Python/2.7/site-packages/pyNN/nest/simulator.py", line 500, in <module>
state = _State() # a Singleton, so only a single instance ever exists
File "/Library/Python/2.7/site-packages/pyNN/nest/simulator.py", line 60, in __init__
self._cache_num_processes = nest.GetKernelStatus()['num_processes'] # avoids blocking if only some nodes call num_processes
AttributeError: 'module' object has no attribute 'GetKernelStatus'
Try using setuptools to install nest with easy_install python-nest.
I am trying something similar, with the further goal of having it working with python 3. So far I used the following commands:
git clone https://github.com/nest/nest-simulator.git
cd nest-simulator
cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr/local/nest -DPYTHON_EXECUTABLE=/usr/local/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/include/python3.5m -DPYTHON_LIBRARY=/usr/local/Cellar/python3/3.5.1/Frameworks/Python.framework/Versions/3.5/lib/libpython3.5.dylib .
make
make install
which runs without errors and I can happily run nest. Iam still having troubles running pyNN (see https://laurentperrinet.github.io/sciblog/posts/2016-06-01-compiling-and-using-pynn-%2B-nest-%2B-python3.html)

Categories