Tag Archives: python

[Solved] Import gensim Error: RuntimeError: Cython extensions are unavailable.

Gensim was installed successfully, but a runtimeerror occurred during import
the runtime error is as follows:
runtimeerror: Python extensions are unavailable. Without them, this gensim functionality is disabled. If you’ve installed from a package, ask the package maintainer to include Python extensions. If you’re building gensim from source yourself, run python setup. py build_ Ext — inplace and retry.
after reading other users’ articles, it is found that numpy and SciPy are incompatible with gensim

The solution steps are as follows

    1. view the python adaptation information, download the adapted numpy and SciPy WHL files, install the WHL files, download the gensim again, and run successfully.

First, check the version information of your Python adaptation before downloading the file
Open CMD and directly enter PIP debug -- verbose on the command line. The results are as follows

after finding it, go to the following link to download the adapted numpy and SciPy files

https://www.lfd.uci.edu/ ~gohlke/pythonlibs/

The corresponding downloaded file on my computer is

After downloading, enter CMD
CD to download SciPy and numpy + MKL
Python – M PIP install scipy-1.7.2-cp37-cp37m-win_ amd64.whl
python -m pip install numpy-1.21.4+mkl-cp37-cp37m-win_ amd64.whl

Then uninstall gensim and install gensim
finally, you can import

[Pytorch Error Solution] Pytorch distributed RuntimeError: Address already in use

The errors reported by pytoch are as follows:

Pytorch distributed RuntimeError: Address already in use

reason:

The port is occupied during model multi card training. Just change the port.

Solution:

Add a parameter — master before running the command_ For example:

 --master_port 29501

The following parameter 29501 can be set to any other port

be careful:

This parameter should be loaded in front of xxx.py, for example:

CUDA_VISIBLE_DEVICES=2,7 python3 -m torch.distributed.run /
--nproc_per_node 2  --master_port 29501  train.py 

[Solved] Flask Error: RuntimeError: The session is unavailable because no secret key was set.

RuntimeError: The session is unavailable because no secret key was set. Set the secret_ key on the application to something unique and secret.

When we run the flash project on the Linux system, we encounter this error:

Solution:

Basically, on the Internet, you can set secret under the flash object app_ Key:
if it is added to the startup file of my project, I can successfully run the project under windows10. If it cannot succeed on the Linux system, it still reports an error

if it is added to the startup file of my project, it can run successfully on Linux

[Solved] Django Error: django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.

1. Background

Because you want to change the default database of Django to MySQL, the following error is reported when starting the project

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.

2. Solution

From the above results, it can be seen that the corresponding module cannot be identified, so the corresponding module needs to be modified __ init__.Py file

import pymysql
pymysql.install_as_MySQLdb()

Just start the service again

[Solved] AttributeError: DataFrame object has no attribute’xxx’

Problem Description:

After reading a column of information in the table (full [‘power ‘]. Describe()),

Error ‘dataframe’ object has no attribute ‘power’ occurred


Problem-solving:

Find the table header and find that there is more space in “power” when naming the header. Delete the space

AttributeError: ‘NoneType‘ object has no attribute ‘shape‘

When training poly-yolo, the environment is debugged, but this bug will appear in the training. Generally, the picture path is not set or set incorrectly.

solve:

In the simulator_ Absolute path is added in front of each line of image in dataset/simulator-train.txt file, such as:

/home/arl/lc/poly-yolo-master/simulator_ dataset/imgs/img_ r_ 12.png

The validation set is the same as above

[Solved] AttributeError: module ‘logging‘ has no attribute ‘Handler‘

Traceback (most recent call last):
  File "/home/odoo/python-dev/python_interview_exercise/python_libs/0-pandas.py", line 3, in <module>
    import numpy
  File "/home/odoo/.local/lib/python3.6/site-packages/numpy/__init__.py", line 223, in <module>
    from .testing import Tester
  File "/home/odoo/.local/lib/python3.6/site-packages/numpy/testing/__init__.py", line 8, in <module>
    from unittest import TestCase
  File "/usr/lib/python3.6/unittest/__init__.py", line 59, in <module>
    from .case import (TestCase, FunctionTestCase, SkipTest, skip, skipIf,
  File "/usr/lib/python3.6/unittest/case.py", line 278, in <module>
    class _CapturingHandler(logging.Handler):
AttributeError: module 'logging' has no attribute 'Handler'

Solution:
the file name is logging.py and renamed to another name, such as demo_logging.py

[Solved] AttributeError: ‘_IncompatibleKeys’ object has no attribute

The error code is as follows:

# Error code!
model = model.load_state_dict(state_dict_var)
out = model(input)

There are some problems on the Internet because the saved model uses state_ DCIT() to load, or vice versa.

The error here is different from the above because xxx.load_state_Dict() does not require a return value to receive.

Amend to read as follows:

# Correct code!
model.load_state_dict(state_dict_var)
out = model(input)

I hope it will help more people.

Resolve – keyerror encountered while installing tensorflow GPU: ‘tensorflow’ error


1. Error content

the error is as follows (example):

ERROR: Exception:
Traceback (most recent call last):
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/resolvelib/resolvers.py", line 171, in _merge_into_criterion
    crit = self.state.criteria[name]
KeyError: 'numpy'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 438, in _error_catcher
    yield
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 519, in read
    data = self._fp.read(amt) if not fp_closed else b""
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/cachecontrol/filewrapper.py", line 62, in read
    data = self.__fp.read(amt)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/http/client.py", line 463, in read
    n = self.readinto(b)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/http/client.py", line 507, in readinto
    n = self.fp.readinto(b)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/socket.py", line 586, in readinto
    return self._sock.recv_into(b)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/ssl.py", line 1012, in recv_into
    return self.read(nbytes, buffer)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/ssl.py", line 874, in read
    return self._sslobj.read(len, buffer)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/ssl.py", line 631, in read
    v = self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_internal/cli/base_command.py", line 189, in _main
    status = self.run(options, args)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_internal/cli/req_command.py", line 178, in wrapper
    return func(self, options, args)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_internal/commands/install.py", line 317, in run
    reqs, check_supported_wheels=not options.target_dir
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 122, in resolve
    requirements, max_rounds=try_to_avoid_resolution_too_deep,
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/resolvelib/resolvers.py", line 453, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/resolvelib/resolvers.py", line 347, in resolve
    failure_causes = self._attempt_to_pin_criterion(name, criterion)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/resolvelib/resolvers.py", line 207, in _attempt_to_pin_criterion
    criteria = self._get_criteria_to_update(candidate)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/resolvelib/resolvers.py", line 199, in _get_criteria_to_update
    name, crit = self._merge_into_criterion(r, parent=candidate)
  File "/home/guest/anaconda3/envs/tf_1.8/lib/python3.6/site-packages/pip/_vendor/resolvelib/resolvers.py", line 173, in _merge_into_criterion

2. Solutions

the input code is as follows:

pip install tensorflow-gpu==1.8.0 --default-timeout=10000 --upgrade

Summary

accumulate more in peacetime and make fewer mistakes in wartime! It’s over

[Solved] Error d8021: invalid numeric parameter “/wno CPP” cython_bbox

Windows system, compiling Python_ Bbox, compile parameters:

from setuptools import setup, find_packages, Extension

import numpy as np

ext_modules = [
    Extension(
        "cython_bbox",
        ["utils/cython_bbox.pyx"],
        extra_compile_args=["-Wno-cpp", "-Wno-unused-function"],
        include_dirs=[np.get_include()],
    )
]

report errors:

Error d8021: invalid numeric parameter “/wno CPP”

Error d8021: invalid numeric parameter “/wno unused function”

Solution:

from setuptools import setup, find_packages, Extension

import numpy as np


ext_modules = [
    Extension(
        "cython_bbox",
        ["utils/cython_bbox.pyx"],
        extra_compile_args=["-std=c++14"],
        include_dirs=[np.get_include()],
    )
]

Or:

        extra_compile_args=["-std=c99"],

Then compile OK:

Resolution of internal server error problem in diango project

Resolution of internal server error problem in diango project

Project scenario:

Django project
using uwsgi deployment
internal server error is found after packaging and running


Problem Description:

internal server error appears on the website of the project. Check the log and find no Python application found

Solution:

Delete uwsgi_ Log restart uwsgi open the uwsgi log file and constantly try to modify it. Open the uwsgi log to check the problem

Cause analysis:

the existing problems are as follows:

    when using pyinstaller to package, do not add – F. the packaged files are still run in the original directory


    Solution:

      put the packaged files in the original directory. Do not use pyinstaller – F manage.spec when running the packaged application
      use pyinstaller manage.spec; Make sure that the python path of the project directory in uwsgi.ini is correct