ImportError when using scipy.io - python

So I am having a bit of trouble using scipy. I have been importing data from a .mat file (matlab variables) and up until today it has worked perfectly. I have no idea what changed or when because I have been developing a text - based data format so that I can avoid depending on Matlab for writing my data. Anyways, I am getting a bizzare import error when I import scipy.io
import scipy.io
myData = scipy.io.loadmat('some_data_file')
When I run this I get the following error:
>>> import scipy.io
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\pyzo2014a\lib\site-packages\scipy\io\__init__.py", line 85, in <module>
from .matlab import loadmat, savemat, whosmat, byteordercodes
File "C:\pyzo2014a\lib\site-packages\scipy\io\matlab\__init__.py", line 13, in <module>
from .mio import loadmat, savemat, whosmat
File "C:\pyzo2014a\lib\site-packages\scipy\io\matlab\mio.py", line 13, in <module>
from .mio4 import MatFile4Reader, MatFile4Writer
File "C:\pyzo2014a\lib\site-packages\scipy\io\matlab\mio4.py", line 11, in <module>
import scipy.sparse
File "C:\pyzo2014a\lib\site-packages\scipy\sparse\__init__.py", line 217, in <module>
from .csgraph import cs_graph_components
File "C:\pyzo2014a\lib\site-packages\scipy\sparse\csgraph\__init__.py", line 148, in <module>
from ._shortest_path import shortest_path, floyd_warshall, dijkstra,\
ImportError: No module named 'scipy.sparse.csgraph._shortest_path'
I thought there might be something wrong with my python distribution so I reinstalled it, however the problem persists, and now the installer says it can't find '_shortest_path.py' when it is installing. When I navigate to .../Libs/site-packages/scipy/sparse/csgraph/ I find that indeed there is no module named _shortest_path. I don't understand how this error came about or how anything in my code would change it. Has anyone else come across this problem?
I am using Pyzo 2014 on Windows 7 x64.

Restore shortest_path.pyd in your virust chest
http://www.blendernation.com/2014/06/28/getting-a-virus-warning-with-blender-2-71-heres-why/

Related

Portable python import of modules does not work

I have a portable python version to use within C:\temp
I wanted to test what version of pandas is included by writing a "scrip"t that import pandas as pd and pritns the pandas version.
I usually start python via the command line which now returned an "Syntax" error in a file that I have never touched.
c:\temp\XXXXApps\RAV\Portable Python 3.2.5.1\App>python.exe packagesTest.py
Traceback (most recent call last):
File "packagesTest.py", line 1, in <module>
import pandas as pd
File "c:\temp\XXXXApps\RAV\Portable Python 3.2.5.1\App\lib\site-packages\pandas\__init__.py", line 27, in <module>
from pandas.core.api import *
File "c:\temp\XXXXApps\RAV\Portable Python 3.2.5.1\App\lib\site-packages\pandas\core\api.py", line 14, in <module>
from pandas.core.frame import DataFrame
File "c:\temp\XXXXApps\RAV\Portable Python 3.2.5.1\App\lib\site-packages\pandas\core\frame.py", line 33, in <module>
from pandas.core.internals import (BlockManager,
File "c:\temp\XXXXApps\RAV\Portable Python 3.2.5.1\App\lib\site-packages\pandas\core\internals\__init__.py", line 1, in <module>
from pandas.core.internals.blocks import ( # io.pytables, io.packers
File "c:\temp\XXXXApps\RAV\Portable Python 3.2.5.1\App\lib\site-packages\pandas\core\internals\blocks.py", line 97
values: Union[np.ndarray, ExtensionArray]
^
SyntaxError: invalid syntax
I am completly new when it comes to these kind of "Error messages". maybe someone can help with what is wrong here.
Pandas Core Internal block

Python3 error when running a pandas simple program

I'm trying to run a python program that uses the pandas library on Mac OS, and I get the next error
adan_vazquez#EPAM-C02G513RML7L automate_python % python3 test_pandas.py
Traceback (most recent call last):
File "/Users/adan_vazquez/Desktop/automate_python/test_pandas.py", line 1, in <module>
import pandas as pd
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/pandas/__init__.py", line 11, in <module>
__import__(dependency)
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/__init__.py", line 155, in <module>
from . import random
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/random/__init__.py", line 180, in <module>
from . import _pickle
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/random/_pickle.py", line 1, in <module>
from .mtrand import RandomState
File "mtrand.pyx", line 1, in init numpy.random.mtrand
File "bit_generator.pyx", line 40, in init numpy.random.bit_generator
File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/secrets.py", line 19, in <module>
from random import SystemRandom
File "/Users/adan_vazquez/Desktop/automate_python/random.py", line 3, in <module>
print(random.randint(1,10))
AttributeError: partially initialized module 'random' has no attribute 'randint' (most likely due to a circular import)
Here's the code that I'm trying to run:
import pandas as pd
simpsons = pd.read_html('https://en.wikipedia.org/wiki/List_of_The_Simpsons_episodes_(seasons_1%E2%80%9320)')
print(len(simpsons))
print("Hola")
As you can see is not a big code and I'm getting the error, I already updated my pip3 and my python3 versions, also I reinstall pandas and I keep getting the error, if I try to import pandas in the python terminal I get the same error and I don't know what's causing it, I hope you can help me, thanks in advance.
The error message says it is a circular import error.
Try renaming /Users/adan_vazquez/Desktop/automate_python/random.py with something other than random
According to the error, it is a circular import which is causing the problem.
Since I do not have the details of your project structure or file name, my best guess is that you accidentally named your working file the same as the module name and those modules depend on each other.

Python requests-html throwing multiprocessing error

I am attempting to move over my web scraping program from using the requests library to the requests-html library to allow me to render the javascript on webpages. On the import of the module this error is thrown:
Traceback (most recent call last):
File "backend2.py", line 2, in <module>
import requests_html
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/requests_html.py", line 9, in <module>
import pyppeteer
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/__init__.py", line 30, in <module>
from pyppeteer.launcher import connect, launch, executablePath # noqa: E402
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/launcher.py", line 24, in <module>
from pyppeteer.browser import Browser
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/browser.py", line 15, in <module>
from pyppeteer.page import Page
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/page.py", line 20, in <module>
from pyppeteer.coverage import Coverage
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/coverage.py", line 15, in <module>
from pyppeteer.util import merge_dict
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/util.py", line 10, in <module>
from pyppeteer.chromium_downloader import check_chromium, chromium_executable
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/pyppeteer/chromium_downloader.py", line 15, in <module>
from tqdm import tqdm
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tqdm/__init__.py", line 1, in <module>
from ._tqdm import tqdm
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/tqdm/_tqdm.py", line 75, in <module>
mp_lock = mp.RLock() # multiprocessing lock
AttributeError: module 'multiprocessing' has no attribute 'RLock'
Any help is appreciated!
You are using Python 3.7, but the github of requests-html states that only Python 3.6 is supported (bottom of page). I get all kinds of horrible errors when I try to use Python 3.7 but 3.6 works fine. So, seems strange I know, but please try using 3.6
Even so, as #georgexsh states, there should still be a RLock available for import from multiprocessing in 3.7 so it looks like your error may actually be that one of your code files is called multiprocessing.py or you have your own package called multiprocessing (so you are importing that instead of the module you wanted).

Error after "from new import instancemethod" when importing scipy.stats

I am getting an exception from scipy whenever I try to import the nltk package. The command and the error looks like this:
>>> import nltk
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/nltk/__init__.py", line 114, in <module>
from nltk.collocations import *
File "/usr/local/lib/python2.7/dist-packages/nltk/collocations.py", line 39, in <module>
from nltk.metrics import ContingencyMeasures, BigramAssocMeasures, TrigramAssocMeasures
File "/usr/local/lib/python2.7/dist-packages/nltk/metrics/__init__.py", line 16, in <module>
from nltk.metrics.scores import (accuracy, precision, recall, f_measure,
File "/usr/local/lib/python2.7/dist-packages/nltk/metrics/scores.py", line 16, in <module>
from scipy.stats.stats import betai
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/__init__.py", line 344, in <module>
from .stats import *
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/stats.py", line 176, in <module>
from . import distributions
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/distributions.py", line 10, in <module>
from ._distn_infrastructure import (entropy, rv_discrete, rv_continuous,
File "/usr/local/lib/python2.7/dist-packages/scipy/stats/_distn_infrastructure.py", line 43, in <module>
from new import instancemethod
File "new.py", line 107
return copy.deepcopy(self)
^
IndentationError: expected an indented block
I executed this command in a terminal (ubuntu 16.04 LTS system). I did not find anything about this error and the indentation doesn't look wrong.
The SyntaxError is in your file new.py (I guess it's in your current working directory). Try to switch to a directory where no new.py file is present (or move the new.py file in another directory), then the internal scipy import should work without problems.
On the other hand you can just upgrade to scipy 0.19.x. They removed the import there and it should work without problems.
Note that it's always a bad idea to name python files like builtin-modules! That's a common source for exceptions or unexpected behaviour.

importing NumPy in Parallel Python

everyone,I am new to PP but got stuck in a problem when importing NumPy with PP.
Basically what I tried to do was submitting a function to the ppserver which depends on NumPy. I have imported it at the very beginning of the code using (import NumPy as nu) but when I ran the code, it gave me the error that cannot find the shared object multiarray.so.
The situation is exactly the same here: parallel python forum
the code is attached as below: (I am running on python 2.7.2 + pp 1.6.0 + numpy 1.5.1)
import numpy as nu
import pylab as pl
import pp
job_server = pp.Server(secret="123456")
print "Starting pp with", job_server.get_ncpus(), "workers"
aa = GrRib()
job = job_server.submit(aa.plotwavefunc, (band,k),(nu,pl,signal))
result = job()
the error looks like :
An error has occured during the function import
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/ppworker.py", line 86, in run
exec __fobj
File "<string>", line 127, in <module>
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python intepreter from there.
An error has occured during the function import
Traceback (most recent call last):
File "/usr/lib/pymodules/python2.7/ppworker.py", line 86, in run
exec __fobj
File "<string>", line 1, in <module>
File "/usr/share/pyshared/matplotlib/__init__.py", line 135, in <module>
from matplotlib.rcsetup import (defaultParams,
File "/usr/share/pyshared/matplotlib/rcsetup.py", line 19, in <module>
from matplotlib.colors import is_color_like
File "/usr/share/pyshared/matplotlib/colors.py", line 52, in <module>
import numpy as np
File "/usr/share/pyshared/numpy/__init__.py", line 136, in <module>
import add_newdocs
File "/usr/share/pyshared/numpy/add_newdocs.py", line 9, in <module>
from numpy.lib import add_newdoc
File "/usr/share/pyshared/numpy/lib/__init__.py", line 4, in <module>
from type_check import *
File "/usr/share/pyshared/numpy/lib/type_check.py", line 8, in <module>
import numpy.core.numeric as _nx
File "/usr/share/pyshared/numpy/core/__init__.py", line 5, in <module>
import multiarray
ImportError: No module named multiarray
Can anyone help me out? I understand it as I will have to change the directory PP is looking for pyshared objects.
I could be wrong, but I believe the way you submit the job is wrong. As seen on the documentation (http://www.parallelpython.com/content/view/15/30/#QUICKSMP), the third argument (not including "self") are dependent functions. Also, the modules have to be strings. I'm assuming the "band" and "k" are dependent functions since I do not see their declarations:
job = job_server.submit(aa.plotwavefunc, depfuncs = (band,k), modules = ("numpy","pylab","signal"))

Categories