Tag Archives: python

Error reporting: attributeerror: module ‘******* has no attribute’ ******* and other problems are solved

Error reported:

resolvent:

1、 Install the third-party library directly on the command page

pip install xxxxxx

  2、 Select interpreter setting in the lower left corner of pychart, click the plus sign, enter the name of the third-party library, and then click Install pakage in the lower left corner to install.

  3、 The 2. X version of tensorflow does not support many third-party libraries. I have tried many methods, but I still think it is the most direct and effective (simple and crude) to install the 1. X version directly. Correspondingly, you may need to downgrade numpy because the installed tensorflow version and numpy version do not match.

Uninstall tensorflow first:

pip uninstall tensorflow

  To install a new version:

pip install tensorflow1.xx

  Check the applicable version of pycharm, and then install:  

pip install tensorflow==1.14 -i https://pypi.douban.com/simple

  After running the code, an error is reported indicating that the numpy version does not match:

For example, I report an error: futurewarning: passing (type, 1) or ‘1type’ as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,))/'(1,)type’.  _ np_ qint32 = np.dtype([(“qint32”, np.int32, 1)])

Recommended installation: or other version

pip install numpy==1.16.0

  Normal operation after.

RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd

After completing the compilation and installation of Caffe, execute import Caffe under Python and report an error:

SystemError: initialization of _caffe raised unreported exception
RuntimeError: module compiled against API version 0xe but this version of numpy is 0xd

My solution is to modify Python in makefile.config_ The include path and numpy (1.16.6) path should be consistent with the virtual environment they use:

PYTHON_INCLUDE := /home/robot/anaconda3/include \
				  /home/robot/anaconda3/envs/zed/include/python3.5m \
				  /home/robot/anaconda3/envs/zed/lib/python3.5/site-packages/numpy/core/include

Django. DB. Utils. Programmingerror: (1146, “table * doesn’t exist”) causes and Solutions

Reason 1:

In the record file generated by each change in the migrations folder in the app, there are operations to delete a table or delete a field, but these modifications are generated in someone else’s environment. When running in your own environment for the first time, you will run the deletion operation first when Python manage. Py migrate , At this time, an error will be reported Django. DB. Utils. Programmingerror: (1146, "table 'doesn't exist")

Reason 2:

The table was called first in the urls.py file.

Error loading in pyinstaller packaging

Error loading “\site-packages\torch\lib\caffe2_ detectron_ ops_ gpu.dll“ or one of its dependencies.

I was tortured by this error when packing. I found various reasons on the Internet. Some people said that there was no Intel OpenMP package in the environment, and others said that there was no cudnn64 in system32_ 7. DLL, others say that the python version in the environment is low and the python version is high… Anyway, I’ve tried many methods, but they’re not very good. But I haven’t tried the last version of Python and python because it’s too troublesome.

terms of settlement

Similar to the above problems that can’t be found, you can solve them by modifying the. Spec
for example, caffe2_ detectron_ ops_ Gpu.dll, I solved the problem by adding Intel OpenMP to hiddenimports
when online solutions are not suitable for you, you’d better read the official documents. Many problems can be solved by writing. Spec files.

[Solved] Pyinstaller Error: “RuntimeError: No metadata path found for distribution ‘greenlet‘

When using pyinstaller to package py file as exe, if the following problems occur

File "c:\xxx\anaconda3\lib\site-packages\PyInstaller\hooks\hook-gevent.py", line 25, in <module>
datas += copy_metadata('gevent', recursive=True)
File "c:\xxx\anaconda3\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 940, in copy_metadata
dest = _copy_metadata_dest(dist.egg_info, dist.project_name)
File "c:\xxx\anaconda3\lib\site-packages\PyInstaller\utils\hooks\__init__.py", line 975, in _copy_metadata_dest
f"No metadata path found for distribution '{project_name}'.")
RuntimeError: No metadata path found for distribution 'greenlet'.

The following methods can be used to solve the problem

pip  install --ignore-installed greenlet 

It is said that the following method (method 2) can also be used to solve the problem. The blogger has not tested this method and does not know whether it is available. It is mainly to have a chance to test it later.

When you encounter this problem, you can uninstall the original one and reinstall it, but this reinstallation will遇到这种问题直接卸载原来的重装但是这个重装会

ERROR: Cannot uninstall ‘greenlet’. It is a distutils installed
project and thus we cannot accurately determine which files belong to
it which would lead to only a partial uninstall.

Then you can just delete this file where you found it according to the address where you reinstalled it.

[Solved] ROS Error: cannot launch node of type [octomap_server/octomap_server_node]:octomap_server

Error log

ERROR: cannot launch node of type [octomap_server/octomap_server_node]: octomap_server
ROS path [0]=/opt/ros/melodic/share/ros

Error reason
this error message says that the node cannot be opened because there is no octomap_ Server type

The problem is that either the path cannot find the octomap server, or the octpmap server is not installed at all

Solution:

sudo apt install ros-melodic-octomap
sudo apt install ros-melodic-octomap-server

Problem solving

Python calendar.month() Error [How to Solve]

When calling calendar.month today, an error is reported. The
code is as follows

import calendar

yy=int(input("year:"))
mm=int(input("month:"))
print(calendar.month(yy,mm))

The error report is shown in the figure below

look at the yellow part circled in the figure. Circular import may be circular. You can see that the program file name is calendar.py, which is consistent with the introduced calendar, so it causes an error.

Solution
just modify the file name, which cannot have the same name as the imported package

[Solved] CentOS7 python import docker Error: No module named selectors

Environmental information

ansible to call the docker module of remote centos7 , you need to install the package docker = = 4.4.4 .

"msg": "Failed to import the required Python library (Docker SDK for Python: docker above 5.0.0 (Python >= 3.6) or docker before 5.0.0 (Python 2.7) or docker-py (Python 2.6)) on k8s-node-56-166.by.com's Python /usr/bin/python. 
Please read the module documentation and install it in the appropriate location. 
If the required library is installed, but Ansible is using the wrong Python interpreter, please consult the documentation on ansible_python_interpreter, for example via `pip install docker` (Python >= 3.6) or `pip install docker==4.4.4` (Python 2.7) or `pip install docker-py` (Python 2.6). The error was: No module named requests.exceptions"

After using pip to install, the following error is still reported:

>>> import docker
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/site-packages/docker/__init__.py", line 2, in <module>
    from .api import APIClient
  File "/usr/lib/python2.7/site-packages/docker/api/__init__.py", line 2, in <module>
    from .client import APIClient
  File "/usr/lib/python2.7/site-packages/docker/api/client.py", line 8, in <module>
    import websocket
  File "/usr/lib/python2.7/site-packages/websocket/__init__.py", line 20, in <module>
    from ._app import WebSocketApp
  File "/usr/lib/python2.7/site-packages/websocket/_app.py", line 23, in <module>
    import selectors
ImportError: No module named selectors
>>> qa
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>

This line of error code comes from

File "/usr/lib/python2.7/site-packages/websocket/_app.py", line 23, in <module>
    import selectors

This file is from the websocket client package.

Observe the detailed installation information as follows:

[root@k8s-node-56-164 ~]# pip install docker==4.4.4
Collecting docker==4.4.4
  Downloading https://files.pythonhosted.org/packages/c4/22/410313ad554477e87ec406d38d85f810e61ddb0d2fc44e64994857476de9/docker-4.4.4-py2.py3-none-any.whl (147kB)
    100% |████████████████████████████████| 153kB 636kB/s 
Requirement already satisfied (use --upgrade to upgrade): six>=1.4.0 in /usr/lib/python2.7/site-packages (from docker==4.4.4)
Requirement already satisfied (use --upgrade to upgrade): ipaddress>=1.0.16; python_version < "3.3" in /usr/lib/python2.7/site-packages (from docker==4.4.4)
Requirement already satisfied (use --upgrade to upgrade): backports.ssl-match-hostname>=3.5; python_version < "3.5" in /usr/lib/python2.7/site-packages (from docker==4.4.4)
Collecting requests!=2.18.0,>=2.14.2 (from docker==4.4.4)
  Downloading https://files.pythonhosted.org/packages/92/96/144f70b972a9c0eabbd4391ef93ccd49d0f2747f4f6a2a2738e99e5adc65/requests-2.26.0-py2.py3-none-any.whl (62kB)
    100% |████████████████████████████████| 71kB 827kB/s 
Collecting websocket-client>=0.32.0 (from docker==4.4.4)
  Downloading https://files.pythonhosted.org/packages/55/44/030ea47390896c8d6dc9995c8e9a4c5df3a161cd45416d88119036c73eda/websocket_client-1.2.1-py2.py3-none-any.whl (52kB)
    100% |████████████████████████████████| 61kB 815kB/s 
Collecting certifi>=2017.4.17 (from requests!=2.18.0,>=2.14.2->docker==4.4.4)
  Downloading https://files.pythonhosted.org/packages/05/1b/0a0dece0e8aa492a6ec9e4ad2fe366b511558cdc73fd3abc82ba7348e875/certifi-2021.5.30-py2.py3-none-any.whl (145kB)
    100% |████████████████████████████████| 153kB 740kB/s 
Collecting urllib3<1.27,>=1.21.1 (from requests!=2.18.0,>=2.14.2->docker==4.4.4)
  Downloading https://files.pythonhosted.org/packages/5f/64/43575537846896abac0b15c3e5ac678d787a4021e906703f1766bfb8ea11/urllib3-1.26.6-py2.py3-none-any.whl (138kB)
    100% |████████████████████████████████| 143kB 4.1MB/s 
Collecting idna<3,>=2.5; python_version < "3" (from requests!=2.18.0,>=2.14.2->docker==4.4.4)
  Downloading https://files.pythonhosted.org/packages/a2/38/928ddce2273eaa564f6f50de919327bf3a00f091b5baba8dfa9460f3a8a8/idna-2.10-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 732kB/s 
Collecting chardet<5,>=3.0.2; python_version < "3" (from requests!=2.18.0,>=2.14.2->docker==4.4.4)
  Downloading https://files.pythonhosted.org/packages/19/c7/fa589626997dd07bd87d9269342ccb74b1720384a4d739a1872bd84fbe68/chardet-4.0.0-py2.py3-none-any.whl (178kB)
    100% |████████████████████████████████| 184kB 610kB/s 
Installing collected packages: certifi, urllib3, idna, chardet, requests, websocket-client, docker
  Found existing installation: chardet 2.2.1
    Uninstalling chardet-2.2.1:
      Successfully uninstalled chardet-2.2.1
Successfully installed certifi-2021.5.30 chardet-4.0.0 docker-4.4.4 idna-2.10 requests-2.26.0 urllib3-1.26.6 websocket-client-1.2.1

docker==4.4.4withwebsocket-client>=0.32.0It is OK
websocket-clientversion is1.2.1

[root@k8s-node-56-164 ~]# pip show websocket-client
---
Metadata-Version: 2.1
Name: websocket-client
Version: 1.2.1
Summary: WebSocket client for Python with low level API options
Home-page: https://github.com/websocket-client/websocket-client.git
Author: liris
Author-email: [email protected]
Installer: pip
License: Apache-2.0
Location: /usr/lib/python2.7/site-packages
...

Solution:

Reduce the version of websocket client to 0.32.0 .

[root@k8s-node-56-164 ~]# pip install websocket-client==0.32.0

The verification is successful, and the ansible call is also successful.

[root@k8s-node-56-164 ~]# python
Python 2.7.5 (default, Nov 16 2020, 22:23:17) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import docker
>>> exit

[Solved] Python Error: positional argument follows keyword argument

Syntax error: position argument follows keyword argument
syntax error: position parameter follows keyword parameter
error example </ font>

def sub(a, b):
    return

s3 = sub(a = 9, 3)
s4 = sub(b = 9, 3)

When a function is called, an error will be reported if the parameter passed (····, formal parameter = argument, argument, ······) occurs
solution:
make the following modifications

def sub(a, b,):
    return
s0 = sub(9,3)
s1 = sub(a=9, b=3)
s2 = sub(9, b = 3)

Clean_pvnet Error: task must be specified [How to Solve]

Run clean_Pvnet encountered the following error: task must be specified

I have never encountered such an error report, and Baidu has not found the relevant results. My heart is impatient, which has plagued me for a long time and I have been unable to think of a solution; After line by line debugging, it is found that there is a problem with the configuration. This is the code written by the author when writing the configuration file, and then modify the parameters one by one to solve the problem of error reporting. We hereby bear in mind that if an error is reported, debug to find the problem first
solution

debug found that the task of the configuration parameter is set to null, resulting in an error. Later, it is modified to pvnet, and cfg.network is also modified

Segmentation fault (core dumped) in open3d operation [Solved]

When using open3d, normal visualization can be performed after the point cloud is established, but it involves calculation, such as calling estimate_ Normals or o3d.pipelines.registration.registration_ ICP, an error segmentation fault (core dumped) will be reported

Solution: import open3d as O3D at the beginning( It seems that the reference order of some packages will affect open3d.)

# Here are my codes below:
pc_pre=o3d.geometry.PointCloud()  
pc_cur=o3d.geometry.PointCloud()
pc_pre.points=o3d.utility.Vector3dVector(pre_cloud)
pc_cur.points=o3d.utility.Vector3dVector(cur_cloud)
res=o3d.pipelines.registration.registration_icp(source=pc_cur,target=pc_pre,
        max_correspondence_distance=threshold)
print(res)

[Solved] Python Error: local variable ‘var‘ referenced before assignment

Unboundlocalerror: local variable ‘var’ referenced before assignment
local variable “var” referenced before assignment

error example 1

var = 10
def f1():
    print(var)
    var = 2
    print(var)
f1()

When VaR is a global variable, it is modified and undeclared in the function

solution:
declare the global variable Global var  before calling

error example 2 

def f2():
    var = 0
    def f3():
        var *= 0
        return var
    return f3()
f2()

VaR is a local variable defined in F2. Its value is modified in nested functions and is not declared
solution:
declare nonlocal var  in nested functions in advance