Tag Archives: python

[Solved] RuntimeError : PyTorch was compiled without NumPy support

I used to use torch 0.4.1, numpy 1.20.1, running error pytorch was compiled without numpy support

later found the following solution
1

pip install numpy==1.15.0

2.upgrade torch-0.4.1to torch-0.4.1.post2

pip install torch==0.4.1.post2

Another error will be reported after using 1 (I forgot the screenshot), which is like this: valueerror: numpy.ufunc size changed, may indicate binary instability. Expected 216 from C header, got 192 from pyobject
after that, I changed the version of numpy to 1.20.1 , Then update torch from torch-0.4.1 to torch-0.4.1. Post2 , so the first step is unnecessary

AttributeError: module ‘keras.backend‘ has no attribute ‘eager‘

Project scenario:

under Windows environment, python 3.6, the versions of each CONDA package are as follows 0

\# Name                    Version                   Build  Channel
absl-py                   0.13.0                    <pip>
astor                     0.8.1                     <pip>
cached-property           1.5.2                     <pip>
certifi                   2021.5.30        py36ha15d459_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
cycler                    0.10.0                    <pip>
dataclasses               0.8                       <pip>
gast                      0.2.2                     <pip>
google-pasta              0.2.0                     <pip>
grpcio                    1.38.1                    <pip>
h5py                      3.1.0                     <pip>
importlib-metadata        4.6.0                     <pip>
joblib                    1.0.1                     <pip>
Keras                     2.3.1                     <pip>
Keras-Applications        1.0.8                     <pip>
Keras-Preprocessing       1.1.2                     <pip>
kiwisolver                1.3.1                     <pip>
Markdown                  3.3.4                     <pip>
matplotlib                3.3.4                     <pip>
numpy                     1.19.5                    <pip>
opt-einsum                3.3.0                     <pip>
pandas                    1.1.5                     <pip>
Pillow                    8.2.0                     <pip>
pip                       21.1.3             pyhd8ed1ab_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
protobuf                  3.17.3                    <pip>
pyparsing                 2.4.7                     <pip>
python                    3.6.13          h39d44d4_0_cpython    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
python-dateutil           2.8.1                     <pip>
python_abi                3.6                     2_cp36m    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
pytz                      2021.1                    <pip>
PyYAML                    5.4.1                     <pip>
scikit-learn              0.24.2                    <pip>
scipy                     1.5.4                     <pip>
seaborn                   0.11.1                    <pip>
setuptools                49.6.0           py36ha15d459_3    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
six                       1.16.0                    <pip>
sklearn                   0.0                       <pip>
tensorboard               1.15.0                    <pip>
tensorflow                1.15.0                    <pip>
tensorflow-estimator      1.15.1                    <pip>
termcolor                 1.1.0                     <pip>
threadpoolctl             2.1.0                     <pip>
typing-extensions         3.10.0.0                  <pip>
ucrt                      10.0.20348.0         h57928b3_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
vc                        14.2                 hb210afc_5    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
vs2015_runtime            14.29.30037          h902a5da_5    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
Werkzeug                  2.0.1                     <pip>
wheel                     0.36.2             pyhd3deb0d_0    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
wincertstore              0.2             py36ha15d459_1006    https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge
wrapt                     1.12.1                    <pip>
zipp                      3.4.1                     <pip>

Problem Description:

it seems that the version of the library that has been adjusted for a long time has finally run through a LSTM demo, but if you want to open a new test file for testing, the following problems appear


Solution:

the solution to stackoverflow is to use the current keras library and tensorflow Library of unitall, because the higher version of keras library may be used, but the running code is of lower version. Note that you need to install tensorflow before installing keras

The specific steps of stackoverflow with the most likes are as follows:
delete tenorflow delete tenorflow

pip uninstall tensorflow

Update PIP version

pip install --upgrade pip

install keras

pip install Keras

install tensorflow

pip install tensorflow

Apart from this method, I want to say that my final solution is: I found the import statement of the keras library

from keras.models import Sequential
from keras.layers import LSTM, Dense, Activation

Cannot appear in two. Py files!!! Even if you just don’t use import, you will still report this error. It’s too bad. I found this problem after reloading it, so when testing the code, you should either create a new project or write the import statement in a file.

AttributeError: module ‘numpy‘ has no attribute ‘getbuffer‘

Numpy. Getbuffer (a) is written in python2, but not in python3. Where a is the numpy array
the following methods can be used instead: a.tobytes(), a.data.tobytes(), memoryview (a). Tobytes(), bytes (a.data), bytes (memoryview (a)) reference link:
https://stackoverflow.com/questions/21821045/numpy-getbuffer-causes-attributeerror-module-object-has-no-attribute-getbuff

TypeError: unsupported operand type(s) for *: ‘range‘ and ‘int‘

This is an error caused by the python2 and python3 versions
in python2, range() returns a list, and you can directly operate range and int
in python3, range() becomes a class. You can’t directly operate on range. You need to add a list first, such as list (range (5))
in order to save memory, range() in python3 only stores the start, stop and step elements of range(), and the rest of the values are calculated one by one, which is actually an iterator. In addition, list() lets range() calculate all the values, and then it can be added.

self._handle = _dlopen(self._name, mode) OSError: [WinError126] The specified module could not found

When doing the project, due to the need to do DLL to speed up, but often burst out error

File "C:\Users\32373\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 434, in LoadLibrary
    return self._dlltype(name)
  File "C:\Users\32373\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 126] The specified module could not be found

The example code is as follows

from ctypes import cdll
class Demo():
	def __init__(self):
		self.__path = "ZeissControl2.dll"
		self.__Library = cdll.LoadLibrary(self.__path)

It’s also a bug that has been bothering me for a long time.
for this problem, I summarize two reasons:

    the first thing is to check whether the path of the DLL file is correct. If it is correct, that is the second reason. When we generate a custom DLL, we usually rely on a variety of other DLL files, so we need to add other DLL files that the DLL calls depends on to the program running directory. In this case, the program can run perfectly in general

    However, in general, in addition to the specified DLL files, user-defined DLL files may also rely on the DLL files of the system environment
    in the latter case, we generally do not know which DLL files we rely on

    Fortunately, Visual Studio provides dumpbin/dependencies tool to get the list of DLL files that the specified DLL depends on
    specific operation
    Start Menu = & gt& gt; visual studio 2017 or 2019 ===>& gt; Developer Command Prompt for VS 2017 or 2019

    After opening the terminal and entering the dumpbin command, you can see that

    we want to view the list of other DLL files that the specified DLL file depends on. The command is as follows

    dumpbin /dependents your_ dll_ path

    For example,

[Solved] RuntimeError (note: full exception trace is shown but execution is paused at: <module>)

Error using multiprocessing module:

from multiprocessing import Process

def hello():
    print('hello')

p = Process(target=hello)
p.start()

Change the code to:

from multiprocessing import Process, freeze_support, set_start_method

def hello():
    print('hello')

if __name__ == '__main__':
    p = Process(target=hello)
    p.start()

Which if __name__ == '__main__':role is to protect the program entry point , when a sub-process using open Process, Python interpreter into the current module, and invoke the hello method, using a simple intuitive test:

from multiprocessing import Process, freeze_support, set_start_method

def hello():
    print('hello')

print("!!!")

if __name__ == '__main__':
    p = Process(target=hello)
    p.start()

In this code, Print ("!!" is not a hello method. Let’s see the running result:

print("!!!") was called twice!!! So before generating a new process, be sure to add if__ name__ == '__ main__':

Further, if you change print("!!!")to print(__name__), you will get the following results:

[Solved] ValueError: check_hostname requires server_hostname

Error prompt:

ERROR: Exception:
Traceback (most recent call last):
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_internal\cli\base_command.py", line 180, in _main
    status = self.run(options, args)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_internal\cli\req_command.py", line 204, in wrapper
    return func(self, options, args)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_internal\commands\install.py", line 318, in run
    requirement_set = resolver.resolve(
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_internal\resolution\resolvelib\resolver.py", line 127, in resolve
    result = self._result = resolver.resolve(
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 473, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 341, in resolve
    name, crit = self._merge_into_criterion(r, parent=None)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_vendor\resolvelib\resolvers.py", line 172, in _merge_into_criterion
    if not criterion.candidates:
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_vendor\resolvelib\structs.py", line 139, in __bool__
    return bool(self._sequence)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 143, in __bool__
    return any(self)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 129, in <genexpr>
    return (c for c in iterator if id(c) not in self._incompatible_ids)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_internal\resolution\resolvelib\found_candidates.py", line 30, in _iter_built
    for version, func in infos:
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_internal\resolution\resolvelib\factory.py", line 258, in iter_index_candidate_infos
    result = self._finder.find_best_candidate(
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_internal\index\package_finder.py", line 879, in find_best_candidate
    candidates = self.find_all_candidates(project_name)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_internal\index\package_finder.py", line 824, in find_all_candidates
    page_candidates = list(page_candidates_it)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_internal\index\sources.py", line 134, in page_candidates
    yield from self._candidates_from_page(self._link)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_internal\index\package_finder.py", line 783, in process_project_url
    html_page = self._link_collector.fetch_page(project_url)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_internal\index\collector.py", line 512, in fetch_page
    return _get_html_page(location, session=self.session)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_internal\index\collector.py", line 422, in _get_html_page
    resp = _get_html_response(url, session=session)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_internal\index\collector.py", line 120, in _get_html_response
    resp = session.get(
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_vendor\requests\sessions.py", line 555, in get
    return self.request('GET', url, **kwargs)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_internal\network\session.py", line 449, in request
    return super().request(method, url, *args, **kwargs)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_vendor\requests\sessions.py", line 542, in request
    resp = self.send(prep, **send_kwargs)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_vendor\requests\sessions.py", line 655, in send
    r = adapter.send(request, **kwargs)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_vendor\cachecontrol\adapter.py", line 53, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_vendor\requests\adapters.py", line 439, in send
    resp = conn.urlopen(
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_vendor\urllib3\connectionpool.py", line 696, in urlopen
    self._prepare_proxy(conn)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_vendor\urllib3\connectionpool.py", line 964, in _prepare_proxy
    conn.connect()
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_vendor\urllib3\connection.py", line 359, in connect
    conn = self._connect_tls_proxy(hostname, conn)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_vendor\urllib3\connection.py", line 500, in _connect_tls_proxy
    return ssl_wrap_socket(
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py", line 432, in ssl_wrap_socket
    ssl_sock = _ssl_wrap_socket_impl(sock, context, tls_in_tls)
  File "d:\python\sdk\py3.9.5\lib\site-packages\pip\_vendor\urllib3\util\ssl_.py", line 474, in _ssl_wrap_socket_impl
    return ssl_context.wrap_socket(sock)
  File "d:\python\sdk\py3.9.5\lib\ssl.py", line 500, in wrap_socket
    return self.sslsocket_class._create(
  File "d:\python\sdk\py3.9.5\lib\ssl.py", line 997, in _create
    raise ValueError("check_hostname requires server_hostname")
ValueError: check_hostname requires server_hostname
WARNING: You are using pip version 21.1.1; however, version 21.1.3 is available.
You should consider upgrading via the 'd:\python\sdk\py3.9.5\python.exe -m pip install --upgrade pip' command.

My Python version:

solution implementation:

pip install  urllib3==1.25.11