h5py not installing properly on canopy? - python

I programme in python and I use a OS X Yosemite version 10.10.2. I have installed h5py 2.5.0-1 in enthought canopy using its package manager. So, h5py 2.5.0-1 has appeared in my installed packages in canopy with a little green tick besides it.
However, when I test it, using the code below or any other code related to h5py, it gives me an error:
This is my test code:
import h5py
import numpy as np
f = h5py.File('test.hdf5', 'w')
This is the error:
1 import h5py
2 import numpy as np
----> 3 f = h5py.File('test.hdf5', 'w')
4
5
AttributeError: 'module' object has no attribute 'File'
As an additional information, my numpy package works properly.Could anybody help me with that please? Thank you very much in advance!

Related

ModuleNotFoundError: No module named 'pycaret.time_series'

I've seen similar questions, but no solutions for this problem.
I'm using Google Colab:
!pip install pycaret
And this:
import time
import numpy as np
import pandas as pd
from pycaret.datasets import get_data
#from pycaret.time_series import TSForecastingExperiment
from pycaret.time_series import *
The last line returns the error: ModuleNotFoundError: No module named 'pycaret.time_series'
Does anyone know how to fix this?
Thanks in advance!
Please follow the instructions here: https://github.com/pycaret/pycaret#-pycaret-time-series-module-beta
Specifically, for the time being, the Time Series module needs to be installed separately in its own environment (i.e. not together with the main pycaret package), using:
!pip install pycaret-ts-alpha

Python - Unable to find assembly 'OSIsoft.AFSDK'

I am trying to import "clr" in a python script and I have an error with and without "clr" installed. If "clr" is installed, then I get the error:
AttributeError: module 'clr' has no attribute 'AddReference'
If I remove "clr" and install pythonnet (as suggested to fix the "clr" error), then I get this error:
FileNotFoundException: Unable to find assembly 'OSIsoft.AFSDK'.
at Python.Runtime.CLRModule.AddReference(String name)
My imports look like this:
import sys
sys.path.append('C:\\Program Files (x86)\\PIPC\\AF\\PublicAssemblies\\4.0\\')
import clr
clr.AddReference('OSIsoft.AFSDK')
from OSIsoft.AF.PI import *
from OSIsoft.AF.Search import *
from OSIsoft.AF.Asset import *
from OSIsoft.AF.Data import *
from OSIsoft.AF.Time import *
import pandas as pd
from datetime import datetime
It seems like I'm missing something in finding the answer. I have loaded the latest oracle client 14.1 and that folder resided in my python working script environment. thank you for any help!
Try to remove be the wrong 'clr' module. which is mixed up with the one in pythonnet.
pip uninstall clr
pip uninstall pythonnet
pip install pythonnet

Can´t import qiskit, attribute error in numpy: " 'numpy.random' has no attribute 'default_rng'"

I´m using Python 3 and I´m working in jupyter, when I try to import qiskit the following error is showed:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-2-578b7f7e9727> in <module>
----> 1 import qiskit
~\AppData\Roaming\Python\Python36\site-packages\qiskit\quantum_info\synthesis\two_qubit_decompose.py in __init__(self, unitary_matrix)
169 # D, P = la.eig(M2) # this can fail for certain kinds of degeneracy
170 for i in range(100): # FIXME: this randomized algorithm is horrendous
--> 171 state = np.random.default_rng(i)
172 M2real = state.normal()*M2.real + state.normal()*M2.imag
173 _, P = la.eigh(M2real)
AttributeError: module 'numpy.random' has no attribute 'default_rng'
I got almost the same error as:
AttributeError: module 'numpy.random' has no attribute 'default_rng'
with the numpy version of '1.16.2'
numpy.__version__
'1.16.2'
As a solution, either you need to put these lines at the top of your file:
import numpy
numpy.random.bit_generator = numpy.random._bit_generator
Or the your current numpy version probably is <= 1.17. Hence, you need to update the NumPy version. For instance, I have updated it on Anaconda environment as:
conda update numpy
And the current version is:
numpy.__version__
'1.19.2'
Updates take time because of lots of dependencies of NumPy. Hopefully, the issue is resolved on my side!
You need NumPy 1.17 or later to have the new RNG functions that Qiskit needs
if you're using jupyter in anaconda - uninstalling, reinstalling and restarting the kernel worked for me similar here: AttributeError: module 'numpy' has no attribute '__version__'
!pip uninstall -y numpy
!pip install numpy
RESTART KERNEL

error "no module named jplephem.pck" when trying to use skyfield

I was trying to work with skyfield and I got the error that:
"ModuleNotFoundError: No module named 'jplephem.pck'"
I get the error in the first line itself
it goes like this:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-6-3a2b53f77cba> in <module>
----> 1 from skyfield.api import load
2
3 planets = load('de421.bsp')
4 earth, mars = planets['earth'], planets['mars']
5
~\Anaconda3\lib\site-packages\skyfield\api.py in <module>
12 from .errors import DeprecationError
13 from .iokit import Loader, load_file
---> 14 from .planetarylib import PlanetaryConstants
15 from .positionlib import position_from_radec
16 from .starlib import Star
~\Anaconda3\lib\site-packages\skyfield\planetarylib.py in <module>
3 import re
4 from numpy import array, cos, einsum, nan, rollaxis, sin
----> 5 from jplephem.pck import DAF, PCK
6 from .constants import ASEC2RAD, AU_KM, DAY_S, tau
7 from .functions import rot_x, rot_y, rot_z
ModuleNotFoundError: No module named 'jplephem.pck'
I tried to look it up on the net and it said that it is a dependency and I do not know what to do to debug this
from skyfield.api import load
planets = load('de421.bsp')
earth, mars = planets['earth'], planets['mars']
ts = load.timescale()
t = ts.now()
position = earth.at(t).observe(mars)
ra, dec, distance = position.radec()
print(ra)
print(dec)
print(distance)
Any form of help will be appreciated
Did you install Skyfield with pip install skyfield, or through another mechanism? Current versions of Skyfield have a setup.py that insists on a recent version of jplephem because only versions more recent than 2.11 will have the pck module that Skyfield needs. The pip install tool should have detected this, but if it did not, doing pip install -U jplephem to force an update of jplephem should get you going again!
Workaround
If you are using conda, you will be installing an old version. Try:
conda uninstall jplephem
pip install -U jplephem
Real solution
The long-term solution is for the conda folks to get their packaging of this library working again. The list of pull requests on their "feedstock" for the library looks like it has encountered repeated failures to build and distribute an up-to-date package:
But the most recent PR is hand-written and has asked for moderator attention, so hopefully things will get fixed.

How can I open a .snappy.parquet file in python?

How can I open a .snappy.parquet file in python 3.5? So far, I used this code:
import numpy
import pyarrow
filename = "/Users/T/Desktop/data.snappy.parquet"
df = pyarrow.parquet.read_table(filename).to_pandas()
But, it gives this error:
AttributeError: module 'pyarrow' has no attribute 'compat'
P.S. I installed pyarrow this way:
pip install pyarrow
I have got the same issue and managed to solve it by following the solutio proposed in https://github.com/dask/fastparquet/issues/366 solution.
1) install python-snappy by using conda install (for some reason with pip install, I couldn't download it)
2) Add the snappy_decompress function.
from fastparquet import ParquetFile
import snappy
def snappy_decompress(data, uncompressed_size):
return snappy.decompress(data)
pf = ParquetFile('filename') # filename includes .snappy.parquet extension
dff=pf.to_pandas()
The error AttributeError: module 'pyarrow' has no attribute 'compat' is sadly a bit misleading. To execute the to_pandas() function on a pyarrow.Table instance you need pandas installed. The above error is a sympton of the missing requirement.
pandas is a not a hard requirement of pyarrow as most of its functionality is usable with just Python built-ins and NumPy. Thus users of pyarrow which include pandas can work with it without needing to have pandas pre-installed.
You can use pandas to read snppay.parquet files into a python pandas dataframe.
import pandas as pd
filename = "/Users/T/Desktop/data.snappy.parquet"
df = pd.read_parquet(filename)

Categories