_pickle.PicklingError: args[0] from __newobj__ args has the wrong class in tensorflow project - python-3.x

code:
# Write vocabulary#
vocab_processor.save(os.path.join(checkpoint_dir, "vocab"))
Error:
Traceback (most recent call last):
File "train.py", line 145, in
vocab_processor.save(os.path.join(checkpoint_dir, "vocab"))
File "/home/chinu/.local/lib/python3.6/site-packages/tensorflow/contrib/learn/python/learn/preprocessing/text.py", line 233, in save
f.write(pickle.dumps(self))
_pickle.PicklingError: args[0] from newobj args has the wrong class

I met the same problem as you. May be you can check this issue and the code changed in it helped me.
The detail in that pull request is to change the following code in preprocesss.py :
self.sup = super(MyVocabularyProcessor,self)
self.sup.__init__(max_document_length,min_frequency,vocabulary,tokenizer_fn)
into the next block.
sup = super(MyVocabularyProcessor,self)
sup.__init__(max_document_length,min_frequency,vocabulary,tokenizer_fn)
tips: Remember to use 2to3 -m filename tool to change other python2 files into python3 ones.

I had a look at the same project https://github.com/dhwajraj/deep-siamese-text-similarity - I had tried Python 3.x but this failed, had to change the Open file with encoding, change xrange to range etc and convert the code back - I ended up at the same issue as you. The code base is Python 2.x and after installing everything as indicated
numpy 1.11.0
tensorflow 1.2.1 (had to downgrade < 1.2 for Python2)
gensim 1.0.1
nltk 3.2.2

Related

H5py Driver Issue on Qiskit Nature Drivers

While using the IBM Quantum experience, whenever I want to install any driver an error with the h5py appears.
Specifically, the error is
"Using default_file_mode other than 'r' is no longer supported. Pass
the mode to h5py.File() instead."
Does anyone have any solutions to it (not sure which version to revert back to). Thanks!!
You will need to add more details about your question. I could not replicate your error based on the information you provided. This is what I did:
First, I installed Qiskit Nature with this command pip install qiskit[nature].
Next, I entered the following Python commands:
>>> from qiskit_nature.drivers.second_quantization import HDF5Driver
>>> h5f = HDF5Driver()
>>> h5f
<qiskit_nature.drivers.second_quantization.hdf5d.hdf5driver.HDF5Driver object at 0x7fa28320a820>
>>> h5f.run()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/virtualenvs/python3/lib/python3.8/site-packages/qiskit_nature/drivers/second_quantization/hdf5d/hdf5driver.py", line 63, in run
raise LookupError(f"HDF5 file not found: {hdf5_file}")
LookupError: HDF5 file not found: molecule.hdf5
There is no error when I imported the HDF5Driver module from the qiskit_nature package. An error occurs when I enter h5f.run(). This is expected, because I don't have a file named molecule.hdf5 (the default filename). If you have a different filename, modify commands above to use h5f = HDF5Driver("your_filename").
Tests run with Python 3.8.12 and qiskit_nature 0.3.0 running on Ubuntu Linux 5.11.0-1023-gcp.

Installation of numpy through Anaconda

getting up to speed on Anaconda, I keep receiving an error message when I try to import 'numpy' into Python.
Here is what I have done so far:
Downloaded anaconda from anaconda.com (64-Bit Graphical
Installer (466 MB) with Python 3.7 for Windows);
Installed anaconda (under C:\Users\'Username'\Anaconda3 | Option 'Register Anaconda3 as my default Python 3.7')
Now I'm trying to import numpy into Python using idle.exe, which produces following error message:
Warning: os.path.expanduser("~") points to
h:\,
but the path does not exist.
Futhermore, after executing "'import 'numpy;" in IDLE I get the following error message.
Unfortunately none of the advice was helpful. Numpy seems to be properly installed.
Warning (from warnings module): File "C:\Users\'Username'\Anaconda3\lib\site-
packages\numpy\__init__.py", line 140
from . import _distributor_init
UserWarning: mkl-service package failed to import, therefore Intel(R) MKL
initialization ensuring its correct out-of-the box operation under condition
when Gnu OpenMP had already been loaded by Python process is not assured.
Please install mkl-service package, see http://github.com/IntelPython/mkl-
service
Traceback (most recent call last):
File "C:\Users\'Username'\Anaconda3\lib\site-packages\numpy\core\__init__.py",
line 24, in <module>
from . import multiarray
File "C:\Users\'Username'\Anaconda3\lib\site-packages\numpy\core\multiarray.py",
line 14, in <module>
from . import overrides
File "C:\Users\'Username'\Anaconda3\lib\site-packages\numpy\core\overrides.py",
line 7, in <module>
from numpy.core._multiarray_umath import (
ImportError: DLL load failed: The specified module could not be found.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\'Username'\Anaconda3\Scripts\myscripts\import_test.py", line 1,
in <module>
import numpy
File "C:\Users\'Username'\Anaconda3\lib\site-packages\numpy\__init__.py", line
142, in <module>
from . import core
File "C:\Users\'Username'\Anaconda3\lib\site-packages\numpy\core\__init__.py",
line 54, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from
"C:\Users\'Username'\Anaconda3\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.1" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: DLL load failed: The specified module could not be found.
Many thanks in advance for any help and suggestions.

ModuleNotFoundError: No module named 'scipy._lib'

I read two or three questions related to this problem but I haven't found any solution yet. I don't understand why I have this error.
I am using Python 3.7 and installed scipyusing the pip installer and it worked properly. For those who want to know, I was testing this program (from this website).
If I go in my Python libraries I have two folders as shown on the image below
Now if I go to the scipy folder, I actually have a _lib folder as shown in the image below. So I don't really understand why this error raised up. And I don't know nor understand what I should do.
I don't have any file called integrate inside this folder, so either I am wrong about where to find the module or I have an obsolete scipy version which seems to be hard to know if you just use the pip installer.
The full error code is:
Traceback (most recent call last):
File "C:\Users\YANN\Desktop\Numerical Method - Python\odeint_example.py", line 2, in <module>
from scipy.integrate import odeint
File "C:\Users\YANN\AppData\Roaming\Python\Python37\site-packages\scipy\__init__.py", line 110, in <module>
from scipy._lib._version import NumpyVersion as _NumpyVersion
ModuleNotFoundError: No module named 'scipy._lib'
Also in the file scipy._lib._version.py the docstring of the NumpyVersion class is shown after and I am wondering if it's ok to have a numpy version 1.15.2? I like my 1.15.2 numpy version...
class NumpyVersion():
"""Parse and compare numpy version strings.
Numpy has the following versioning scheme (numbers given are examples; they
can be >9) in principle):
- Released version: '1.8.0', '1.8.1', etc.
- Alpha: '1.8.0a1', '1.8.0a2', etc.
- Beta: '1.8.0b1', '1.8.0b2', etc.
- Release candidates: '1.8.0rc1', '1.8.0rc2', etc.
- Development versions: '1.8.0.dev-f1234afa' (git commit hash appended)
- Development versions after a1: '1.8.0a1.dev-f1234afa',
'1.8.0b2.dev-f1234afa',
'1.8.1rc1.dev-f1234afa', etc.
- Development versions (no git hash available): '1.8.0.dev-Unknown'
Comparing needs to be done against a valid version string or other
`NumpyVersion` instance.
Parameters
----------
vstring : str
Numpy version string (``np.__version__``).
Notes
-----
All dev versions of the same (pre-)release compare equal.
Examples
--------
>>> from scipy._lib._version import NumpyVersion
>>> if NumpyVersion(np.__version__) < '1.7.0':
... print('skip')
skip
>>> NumpyVersion('1.7') # raises ValueError, add ".0"
"""
Any tips will be very appreciated! :)

Problems using ambhas package: statistics module has no cpdf attribute

I am trying to use the ambhas package for copulas and the method
foo.generate_xy()
is not working.
This is error I get:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
generate()
File "C:/Users/Mypc/Desktop/sfsdf.py", line 19, in genera
x1,y1 = foo.generate_xy()
File "C:\Python33\lib\site-packages\ambhas\copula.py", line 179, in generate_xy
self._inverse_cdf()
File "C:\Python33\lib\site-packages\ambhas\copula.py", line 256, in _inverse_cdf
x2, x1 = st.cpdf(self.X, kernel = 'Epanechnikov', n = 100)
AttributeError: 'module' object has no attribute 'cpdf'
Basically I checked the code in the ambhas module and it turns out it is trying to use a method from the statistics module (imported as st), st.cpdf() which I do not have in my statistics module.
How can I fix this problem?
Here is an example of the code working. This is the very same code I am trying to run through the generate() function:
https://code.google.com/p/ambhas/wiki/Cookbook
The AMBHAS code depends on this statistics module, not the "official" one that is now included in Python 3.4. Unfortunately, the module doesn't appear to have been updated in a while, and the latest Windows installer is for Python 3.2, so you'll need to build it from source. You can do this with Cygwin, or by installing Visual C++ 2010 Express (here is a blog post describing the process, but I haven't tried it myself so I don't know if it's completely accurate - YMMV).
Once you've compiled the extension, make sure you remove the statistics module you installed previously before running python setup.py install.

Python, PySerial and cx-freeze

Trying to learn cx-freeze. I have a python program that I am trying freeze to exe.
I use PySerial and no matter how I try to include win32 nothing seems to help. I use Python 3.2 and win7.
I have searched the web thin, and others have had the same problem, but no solution seems to be appearing. But I doubt that no one have succeeded in cx_freezing something that uses PySerial.
I am completely stuck. Any help would be much appreciated
Error:
Traceback (most recent call last):
File "C:\Python32\lib\site-packages\
7, in <module>
exec(code, m.__dict__)
File "snapper.py", line 8, in
File "C:\Python32\lib\site-packages\
from serial.serialwin32 import *
File "C:\Python32\lib\site-packages\
e>
from serial import win32
ImportError: cannot import name win32
Setup.py:
from cx_Freeze import setup,Executable
includefiles = ['caml.pkl', 'seql.pkl']
includes = ['DataBase', 'serial.win32']
excludes = ['Tkinter']
packages = []
setup(
name = 'Setup',
version = '0.1',
description = 'Snapper configuration utility',
author = 'LST',
author_email = 'info#-.com',
options = {'build_exe': {'excludes':excludes,'packages':packages,'include_files':includefiles}},
executables = [Executable('snapper.py')]
)
Any idea where to go from here?
Thanks in advance
I tried to do a blind import:
if False:
import serial.win32
no luck...
Maybe i am looking at this the wrong way....
Okay, problem solved.
You need to use packages to force cx_Freeze to include serial.win32 (not "include")
Following line works:
packages = ['serial.win32']
Memo to my self and others: Be sure to check the dist folder for actually included packages. I have no idea why all packages didn't get included by cx_Freeze in the first place, but this works for me.
If you can use a different tool to freeze your program, PyInstaller says it supports PySerial.

Resources