NameError: name 'os_PathLike' is not defined - python-3.x

I wanted to load text into a numpy array. I have used the code below:
import numpy as np
import os
a = np.loadtxt(os.getcwd()+'abc.txt')
But I am getting an error as follows:
File "/Users/vivekchowdary/opt/anaconda3/lib/python3.7/site-packages/numpy/lib/npyio.py", line 965, in loadtxt
NameError: name 'os_PathLike' is not defined
Can anyone help me with what's going wrong with my code?

Related

Rdkit: MaeMolSupplier NameError

I would like to able to extract details about a molecule in ".mae" format. I imported the rdkit.Chem.rdmolfiles functions and it seems to work for MolFromSmiles, but not for MaeMolSupplier as suggested in the 2019 documentation. Instead I get a NameError. Any aid/help in calling this function would be greatly appreciated.
Works OK with MolFromSmiles
import rdkit
from rdkit.Chem.rdmolfiles import *
mol = MolFromSmiles('C1NCN1')
print(mol)
(my-rdkit-env) [Me]$ python3 testrdkit.py
<rdkit.Chem.rdchem.Mol object at 0x7f237f917030>
Now to show the error
import rdkit
from rdkit.Chem.rdmolfiles import *
suppl = MaeMolSupplier(file('five.mae'))
print(suppl)
my-rdkit-env) [Me]$ python3 testrdkit.py
Traceback (most recent call last):
File "testrdkit.py", line 8, in <module>
suppl = MaeMolSupplier(file('five.mae'))
NameError: name 'MaeMolSupplier' is not defined
import * doesn't work here either.
Just import rdmolfiles.
from rdkit.Chem import rdmolfiles
suppl = rdmolfiles.MaeMolSupplier('five.mae')
print(suppl)
<rdkit.Chem.rdmolfiles.MaeMolSupplier object at 0x000002792CEFC5B0>

Pandas ImportError

Whenever I try to import pandas as pd it shows the error
ImportError: cannot import name 'window' from 'pandas.core' (//anaconda3/lib/python3.7/site-packages/pandas/core/__init__.py)

AttributeError: module 'typing' has no attribute 're' in pandas Python 3.7

I can't import pd from pandas because i have this error. I search on google but I didn't find the fix for this..
>>> import pandas
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python37\lib\site-packages\pandas\__init__.py", line 23, in <module>
from pandas.compat.numpy import *
File "C:\Python37\lib\site-packages\pandas\compat\__init__.py", line 431, in <module>
re_type = typing.re.Pattern
AttributeError: module 'typing' has no attribute 're'
I think this is changing underneath us as Python's typing module matures, but in our case, the issue was that we did from Typing import re, and then later did something like:
def funct(some_re: re.Pattern):
The fix was dumb. Simply change your import to be from typing import Pattern and then do:
def funct(some_re: Pattern):
Bleh. Warts.

Pickle can't be load for Pascal VOC pickle dataset

I'm trying to load Pascal VOC dataset from Stanford website here. Also trying to implement a code from Semantic Image Segmentation on Pascal VOC Pystruct blog. But I'm getting UnicodeDecodeError when I tried to load the pickle file. I tried below code so far:
import numpy as np
try:
import cPickle as pickle
except ImportError:
import pickle
from pystruct import learners
import pystruct.models as crfs
from pystruct.utils import SaveLogger
data_train = pickle.load(open("trainingData/data_train.pickle"))
C = 0.01
And I got this errror:
Traceback (most recent call last):
File "/Users/mypath/PycharmProjects/semantic_segmentation_ex/ex1.py", line 11, in <module>
data_train = pickle.load(open("trainingData/data_train.pickle"))
File "/usr/local/Cellar/python3/3.6.2/Frameworks/Python.framework/Versions/3.6/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0: ordinal not in range(128)
I couldn't find any same problem and solution. How do I get this to work?
One of my friend told me the reason. Serialized object is a python2 object, so if you load with Python2, it's opening directly without any problem.
But If you would like to load with Python3, you need to add encoding parameters to pickle not into open function. Here is sample code:
import numpy as np
try:
import cPickle as pickle
except ImportError:
import pickle
with open('data_train.pickle', 'rb') as f:
# If you use Python 3 needs a parameter as encoding='bytes'
# Otherwise, you shouldn't add encoding parameters in Python 2
data_train = pickle.load(f, encoding='bytes')
print("Finished loading data!")
print(data_train.keys())
Special thanks to #ahmet-sezgin-duran

ImportError: cannot import name 'mutual_info_classif'

I want to do feature selection using K-Best and scoring function 'mutual_info_classif' in scikitlearn. However I am not able to import this function because of this error:
ImportError: cannot import name 'mutual_info_classif'

Resources