标签: attributeerror

PyInstaller:AttributeError“模块”对象没有属性“注册”

我正在开发一个大型 python 项目,最后脚本由 PyInstaller 打包。上周我打包和运行我的应用程序没有遇到任何问题。这周我打包脚本时没有出现任何错误。然而,当我现在运行我的可执行文件时,我似乎遇到了一个相当普遍的错误,但来自一个奇怪的来源:

    Traceback (most recent call last):
  File "<string>", line 120, in <module>
  File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 271, in load_module
    exec(bytecode, module.__dict__)
  File "/tmp/build/tmpDJZeLr/out00-PYZ.pyz/encodings", line 157, in <module>
AttributeError: 'module' object has no attribute 'register'
Run Code Online (Sandbox Code Playgroud)

我在我的代码中查找罪魁祸首,但我的项目中没有一个名为“注册”的属性/函数/等。我尝试在自己的代码中添加一些调试语句,但在弹出此错误之前,我的脚本中没有一个函数被调用。

然后我决定在 pyi_importers.py 中第 70 行附近添加一些打印语句:

            sys.modules[fullname] = module
            # Run the module code.
            print module
            print module.__dict__
            print bytecode
            exec(bytecode, module.__dict__)
Run Code Online (Sandbox Code Playgroud)

结果是:

<module 'encodings.aliases' from '/tmp/_MEIbDiUZq/encodings/aliases.pyc'>
{'__name__': 'encodings.aliases', '__file__': '/tmp/_MEIbDiUZq/encodings/aliases.pyc', '__loader__': <pyi_importers.FrozenImporter object at 0x7f1666fa0d10>, '__doc__': None, '__package__': 'encodings'}
<code object <module> …
Run Code Online (Sandbox Code Playgroud)

python pyinstaller attributeerror

1
推荐指数
1
解决办法
4634
查看次数

AttributeError:“bool”对象没有属性“items”

我是Python的初学者。我目前正在尝试使用 IK 来移动机器人手臂。当我尝试运行我的程序时,手臂能够移动到我设置的起始位置,但是当它进入下一步时,它会向我显示以下错误:AttributeError: 'bool' object has no attribute 'items'

这是我的程序:

class Pick_Place (object):

    #def __init__(self,limb,hover_distance = 0.15):
    def __init__(self,limb):
       self._limb = baxter_interface.Limb(limb)
       self._gripper = baxter_interface.Gripper(limb)
       self._gripper.calibrate(limb)
       #self.gripper_open()
       #self._verbose = verbose
       ns = "ExternalTools/" + limb + "/PositionKinematicsNode/IKService"
       self._iksvc = rospy.ServiceProxy(ns,SolvePositionIK) 
       rospy.wait_for_service(ns, 5.0)

    def move_to_start (self,start_angles = None):

            print ("moving.....")
            if not start_angles:
                print ("it is 0")
                start_angles = dict(zip(self._joint_names, [0]*7))

            self._guarded_move_to_joint_position(start_angles)
            self.gripper_open()
            rospy.sleep(1.0)
            print ("moved!!!")

#########################IK_Server################################################
    def ik_request (self,pose):
        hdr = Header(stamp=rospy.Time.now(),frame_id='base')
        ikreq = SolvePositionIKRequest()
        ikreq.pose_stamp.append(PoseStamped(header=hdr, pose=pose))
        try:
            resp …
Run Code Online (Sandbox Code Playgroud)

python attributeerror

1
推荐指数
1
解决办法
4万
查看次数

Python SqlAlchemy - AttributeError:映射器

基于我的模型:

from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, ForeignKey
from sqlalchemy.orm import relationship

Base = declarative_base()

class Session(Base):
    __tablename__ = 'sessions'

    id = Column(Integer, primary_key=True)
    token = Column(String(200))
    user_id = Column(Integer, ForeignKey('app_users.id'))
    user = relationship('model.user.User', back_populates='sessions')
Run Code Online (Sandbox Code Playgroud)

我想通过以下方式实例化一个新会话:

session = Session(token='test-token-123')
Run Code Online (Sandbox Code Playgroud)

但我得到:

AttributeError: mapper
Run Code Online (Sandbox Code Playgroud)

完整的堆栈跟踪:

Traceback (most recent call last):
  File "/home/ubuntu/.local/lib/python3.5/site-packages/falcon/api.py", line 227, in __call__
    responder(req, resp, **params)
  File "./app_user/register.py", line 13, in on_post
    session = Session(token='test-token-123')
  File "<string>", line 2, in __init__
  File "/home/ubuntu/.local/lib/python3.5/site-packages/sqlalchemy/orm/instrumentation.py", line 347, …
Run Code Online (Sandbox Code Playgroud)

python orm sqlalchemy attributeerror falconframework

1
推荐指数
1
解决办法
6540
查看次数

序列化程序 django rest 框架上字段值的属性错误

我收到以下错误:

AttributeError: Got AttributeError when attempting to get a value for field `city` on serializer `SearchCitySerializer`
Run Code Online (Sandbox Code Playgroud)

我的序列化程序是正确的,除非我明显遗漏了一些东西。

这是我的模型:

class SearchCity(models.Model):
    city = models.CharField(max_length=200)
Run Code Online (Sandbox Code Playgroud)

这是我的序列化程序

class SearchCitySerializer(serializers.ModelSerializer):
    class Meta:
        model = SearchCity
        fields = ('pk','city')
Run Code Online (Sandbox Code Playgroud)

*** 我在没有 pk 的情况下尝试了序列化程序,但仍然失败

在这里它在视图中使用:

 from serializers import SearchCitySerializer

 def get(self, request, format=None):
        searchcityqueryset = SearchCity.objects.all()
        serializedsearchcity = SearchCitySerializer(searchcityqueryset)

        return Response({
            'searchcity': serializedsearchcity.data,
        })
Run Code Online (Sandbox Code Playgroud)

我得到的完整错误:

File "/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/backend/virtualsuits/suitsandtables/suitsandtablessettingsapp/views.py", line 37, in get
    'searchcity': serializedsearchcity.data,
  File "/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/backend/virtualsuits/local/lib/python2.7/site-packages/rest_framework/serializers.py", line 537, in data
    ret = super(Serializer, self).data
  File "/home/rickus/Documents/softwareProjects/211hospitality/suitsandtables/backend/virtualsuits/local/lib/python2.7/site-packages/rest_framework/serializers.py", line …
Run Code Online (Sandbox Code Playgroud)

django serialization model attributeerror django-rest-framework

1
推荐指数
1
解决办法
2047
查看次数

AttributeError: 'float' 对象在使用 seaborn 时没有属性 'shape'

我创建了一个随机数据框来模拟来自seaborn的数据集提示

import numpy as np
import pandas as pd

time = ['day','night']
sex = ['female','male']
smoker = ['yes','no']
for t in range(0,len(time)):
    for s in range(0,len(sex)):
        for sm in range(0,len(smoker)):
            randomarray = np.random.rand(10)*10
            if t == 0 and s == 0 and sm == 0:
                df = pd.DataFrame(index=np.arange(0,len(randomarray)),columns=["total_bill","time","sex","smoker"])
                L = 0
                for i in range(0,len(randomarray)):
                    df.loc[i] = [randomarray[i], time[t], sex[s], smoker[sm]]
                    L = L + 1
            else:
                for i in range(0,len(randomarray)):
                    df.loc[i+L] = [randomarray[i], time[t], sex[s], …
Run Code Online (Sandbox Code Playgroud)

python attributeerror seaborn

1
推荐指数
1
解决办法
7918
查看次数

如何修复:AttributeError:模块“neat”没有属性“config”

我正在浏览使用此处找到的 NEAT 神经网络 API 播放飞扬小鸟的 AI 的指南。

当我运行他从 Github 下载的代码时,它给了我错误:

 "Traceback (most recent call last):
  File "test.py", line 438, in <module>
    run(config_path)
  File "test.py", line 412, in run
    config = neat.config.Config(neat.DefaultGenome, neat.DefaultReproduction,
AttributeError: module 'neat' has no attribute 'config'
Run Code Online (Sandbox Code Playgroud)

问题似乎来自这段代码:

def run(config_file):
    """
    runs the NEAT algorithm to train a neural network to play flappy bird.
    :param config_file: location of config file
    :return: None
    """
    config = neat.config.Config(neat.DefaultGenome, neat.DefaultReproduction,
                         neat.DefaultSpeciesSet, neat.DefaultStagnation,
                         config_file)

    # Create the population, which is …
Run Code Online (Sandbox Code Playgroud)

python config artificial-intelligence attributeerror neural-network

1
推荐指数
1
解决办法
5773
查看次数

AttributeError: 'bytes' 对象没有属性 'element_to_be_clickable'

AttributeError: 'bytes' 对象没有属性 'element_to_be_clickable'

from telnetlib import EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from time import sleep
from selenium.webdriver.support.select import Select

select = Select(wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="form-validation-field-0"]'))))
AttributeError: 'bytes' object has no attribute 'element_to_be_clickable'
Run Code Online (Sandbox Code Playgroud)

python selenium attributeerror pycharm selenium-webdriver

1
推荐指数
1
解决办法
1781
查看次数

无法使用 tf.contrib

我导入了 tensorflow 模块,但无法使用 tf.contrib。我不知道是什么问题。我尝试在不同版本中运行它,但我一直得到相同的输出。

模块导入:

import tensorflow.compat.v1 as tf1
tf1.disable_v2_behavior() 
import tensorflow as tf2
Run Code Online (Sandbox Code Playgroud)

代码:

tf2.contrib.rnn.LSTMCell(num_units=num_nodes[li],
                            state_is_tuple=True,
                            initializer= tf.contrib.layers.xavier_initializer()
                           )
Run Code Online (Sandbox Code Playgroud)

输出:

AttributeError: module 'tensorflow' has no attribute 'contrib'
Run Code Online (Sandbox Code Playgroud)

python machine-learning attributeerror lstm tensorflow

1
推荐指数
1
解决办法
4086
查看次数

AttributeError:“NoneType”对象没有属性“copy”

完整的错误是:


    OpenCV: out device of bound (0-0): 1
    OpenCV: camera failed to properly initialize!
    Traceback (most recent call last):
      File "/Users/syedrishad/PycharmProjects/OpenCVPython/venv/project1.py", line 60, in <module>
        imgResult = img.copy()
    AttributeError: 'NoneType' object has no attribute 'copy'
     ```

Run Code Online (Sandbox Code Playgroud)

完整代码是:

```import cv2
import numpy as np

frameWidth = 640
frameHeight = 480
cap = cv2.VideoCapture(1)
cap.set(3, frameWidth)
cap.set(4, frameHeight)
cap.set(10, 150)

myColors = [[78, 119, 70, 255, 97, 255],
            [63, 108, 44, 255, 0, 118],
            [0, 179, 69, 255, 100, 255],
            [90, 48, …
Run Code Online (Sandbox Code Playgroud)

python opencv object attributeerror nonetype

1
推荐指数
1
解决办法
5万
查看次数

AttributeError: 'CallbackContext' ('Update') 对象没有属性 'message'

将我的 tg-bot 转移到新服务器后出现问题。完全不知道为什么我有错误。好像我丢失了一些要安装的 python 数据包。在具有相同操作系统参数的旧服务器中,我对这个机器人没有任何问题。

对不起,如果我的错误幼稚。我试着用谷歌搜索我的错误,但没有答案。

代码1:

def start(bot, update):
    if update.message.from_user.username == AAA:
        bot.sendMessage(chat_id=update.message.chat_id, text="Text_one")
    else:
        bot.sendMessage(chat_id=update.message.chat_id, text="Text_two")
...
updater = Updater(token=bot_token)

start_handler = CommandHandler('start', start)
updater.dispatcher.add_handler(start_handler)
Run Code Online (Sandbox Code Playgroud)

错误 1:

File "/usr/local/lib/python3.7/site-packages/telegram/ext/dispatcher.py", line 425, in process_update handler.handle_update(update, self, check, context)
File "/usr/local/lib/python3.7/site-packages/telegram/ext/handler.py", line 145, in handle_update return self.callback(update, context)
File "./bot.py", line 43, in start
if update.message.from_user.username == AAA:
AttributeError: 'CallbackContext' object has no attribute 'message'
Run Code Online (Sandbox Code Playgroud)

代码2:

def rating(bot, update):
    bot.send_sticker(chat_id,'some_sticker_id')
...
rating_handler = CommandHandler('rating', rating)
updater.dispatcher.add_handler(rating_handler)
Run Code Online (Sandbox Code Playgroud)

错误2:

File "/usr/local/lib/python3.7/site-packages/telegram/ext/dispatcher.py", …
Run Code Online (Sandbox Code Playgroud)

attributeerror python-3.x telegram-bot

1
推荐指数
1
解决办法
2558
查看次数