在我的 Jupyter Notebook 中出现此错误 使用 conda 而不是 pip 解决此问题的最佳方法是什么
我已经尝试过conda upgrade --all,但似乎不起作用
我正在 Kaggle 服务器上运行 .ipynb 笔记本。
在第一个代码单元中,导入模块时,特别是来自 google.patches 的 cv2_imshow,如下所示,
from google.colab.patches import cv2_imshow
我收到此错误:
/opt/conda/lib/python3.7/site-packages/IPython/utils/traitlets.py:5: UserWarning: IPython.utils.traitlets has moved to a top-level traitlets package.
warn("IPython.utils.traitlets has moved to a top-level traitlets package.")
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
/tmp/ipykernel_27/1840971195.py in <module>
18
19 # Display images using OpenCV
---> 20 from google.colab.patches import cv2_imshow # Importing cv2_imshow from google.patches to display images
21
22 # Ignore warnings
/opt/conda/lib/python3.7/site-packages/google/colab/__init__.py in <module>
24 from google.colab import _tensorflow_magics
25 from google.colab import …Run Code Online (Sandbox Code Playgroud) module attributeerror kaggle google-colaboratory python-traitlets
我有最新版本的 pandas,2.0.1。
这个简单的代码:
import pandas
pandas.Int64Index
Run Code Online (Sandbox Code Playgroud)
给出错误:
AttributeError: module 'pandas' has no attribute 'Int64Index'
Run Code Online (Sandbox Code Playgroud)
我尝试使用pip和卸载并重新安装 pandas conda,还重新启动了 Jupyter 笔记本,但仍然收到错误。
尝试学习即将到来的期末考试时出现此错误,需要了解它为什么不起作用.这是代码.
morning_agenda = "At 9.00AM the project team will assemble. The first topic will be fixing the bug in program product.py. We'll break for coffee at 10.30. Work will then continue on improving display.html until 12.30PM."
print morning_agenda
morning_agenda.sub('([0-9]+)\.([0-9]+)', r'\1:\2', morning_agenda)
print morning_agenda
Run Code Online (Sandbox Code Playgroud) 我在使用Python 3.3 32位的Windows上工作.我已经安装了peewee并想尝试它的一些功能.我已经开始使用Peewee Quickstart(http://peewee.readthedocs.org/en/latest/peewee/quickstart.html).
我的代码看起来像这样:
from peewee import *
db = SqliteDatabase('people.db')
class Person(Model):
name = CharField()
birthday = DateField()
is_relative = BooleanField()
class Meta:
database = db
class Pet(Model):
owner = ForeignKeyField(Person, related_name = "pets")
name = CharField()
animal_type = CharField()
class Meta:
database = db
Person.create_table()
Pet.create_table()
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
File "<stdin>", line 1, in <module>
File "<string>", line 21, in <module>
File "C:\Python33\lib\site-packages\peewee.py", line 2094, in create_table
db = cls._meta.database
AttributeError: type object 'Person' has no attribute …Run Code Online (Sandbox Code Playgroud) 这似乎只是一个我无法弄清楚的简单错误.我在C#WPF应用程序中使用IronPython,并在尝试从自定义C#类运行函数时收到以下错误:AttributeError: 'MyScriptingFunctions' object has no attribute 'Procedure'.
我正在运行的python脚本非常简单,有两行.第1行执行正常,错误发生在第2行.
txt.Text = "some text"
MyFunc.Procedure(5)
Run Code Online (Sandbox Code Playgroud)
MyScriptingFunctions.cs:
class MyScriptingFunctions
{
public MyScriptingFunctions() {}
public void Procedure(int num)
{
Console.WriteLine("Executing procedure " + num);
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我设置IronPython引擎的方法:
private void btnRunScript_Click(object sender, RoutedEventArgs e)
{
MyScriptingFunctions scriptFuncs = new MyScriptingFunctions();
ScriptEngine engine = Python.CreateEngine();
ScriptScope scope = engine.CreateScope();
ScriptRuntime runtime = engine.Runtime;
runtime.LoadAssembly(typeof(String).Assembly);
runtime.LoadAssembly(typeof(Uri).Assembly);
//Set Variable for the python script to use
scope.SetVariable("txt", fullReadResultsTextBox);
scope.SetVariable("MyFunc", scriptFuncs);
string code = this.scriptTextBox.Text;
try
{
ScriptSource …Run Code Online (Sandbox Code Playgroud) 尝试运行以下代码时出现属性错误:
import cv2
import cv2.cv as cv
import numpy as np
def main():
img = cv2.imread('images/g1.jpg',0);
print(img)
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
circles = cv2.HoughCircles(img, cv.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
# draw the outer circle
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
# draw the center of the circle
cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
cv2.imshow('detected circles',cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
我试图找到解决这个问题的方法,我用了cv2替换cv了
circles = cv2.HoughCircles(img, cv.HOUGH_GRADIENT, 1, 20, param1=50, param2=30, minRadius=0, maxRadius=0)
Run Code Online (Sandbox Code Playgroud)
但是,我仍然得到错误.
我试图在QGIS Python控制台中使用QString.
from PyQt4.QtCore import QString
Run Code Online (Sandbox Code Playgroud)
但它说:
ImportError: cannot import name QString
Run Code Online (Sandbox Code Playgroud)
在我的Python IDLE中它工作正常,但我知道QGIS带来了自己的PyQt4.这可能是什么问题?我能解决吗?
import PyQt4.QtCore
PyQt4.QtCore.QString()
Run Code Online (Sandbox Code Playgroud)
和
from PyQt4 import QtCore
QtCore.QString()
Run Code Online (Sandbox Code Playgroud)
无论如何都不行.
我正在考虑将QtCore4.dll从我自己的PyQt4安装复制到QGIS,但QGIS使用QtCore.prl和QtCore4.lib而不是QtCore.pyd和QtCore4.dll,就像我的PyQt4安装一样
当我在QGIS控制台中调用帮助(PyQt4.QtCore)时,它没有说明QString类,而Python IDLE中的操作也是如此......这真的令人沮丧......
如果有人知道该做什么会很棒:)
这是我的代码:
import docx
doc = docx.Document()
doc.add_paragraph('This is on first page!')
doc.paragraphs[0].runs[0].add_break(docx.text.WD_BREAK.PAGE)
doc.add_paragraph('This is on the second page!')
doc.save('twoPage.docx')
Run Code Online (Sandbox Code Playgroud)
错误是:
AttributeError: 'module' object has no attribute 'WD_BREAK'
Run Code Online (Sandbox Code Playgroud) 我正在使用python 3.6,并且在运行下面的代码时,我得到了一条错误消息,该消息显示
Traceback(最近一次调用是最近一次):文件“ C:/Users/Sagar/AppData/Local/Programs/Python/Python36-32/graphfile.py ”,在plt.plot(x,y)中的第10行AttributeError:模块'matplotlib'没有属性'plot'
该代码是
import matplotlib as plt
x=[]
y=[]
readfile=open("graph.txt","r")
data=readfile.read().split("\n")
for i in data:
val=i.split(",")
x.append(int(val[0]))
y.append(int(val[1]))
plt.plot(x,y)
plt.show()
Run Code Online (Sandbox Code Playgroud)