本文将带您了解关于RuntimeWarning:numpy.dtype大小已更改,可能表明二进制不兼容的新内容,同时我们还将为您解释importnumpycouldnotberesolved的相关知识
本文将带您了解关于RuntimeWarning:numpy.dtype大小已更改,可能表明二进制不兼容的新内容,同时我们还将为您解释import numpy could not be resolved的相关知识,另外,我们还将为您提供关于Asyncio如何修复sys:1:RuntimeWarning:从未等待协程'xxx'、c – warning:返回类型默认为’int'[-Wreturn-type]、Django:RunTimeWarning:DateTimeField在时区支持处于活动状态时收到了一个简单的日期时间、DtypeWarning: Columns (1,5,7,16,......) have mixed types. Specify dtype option on import or set l...的实用信息。
本文目录一览:- RuntimeWarning:numpy.dtype大小已更改,可能表明二进制不兼容(import numpy could not be resolved)
- Asyncio如何修复sys:1:RuntimeWarning:从未等待协程'xxx'
- c – warning:返回类型默认为’int'[-Wreturn-type]
- Django:RunTimeWarning:DateTimeField在时区支持处于活动状态时收到了一个简单的日期时间
- DtypeWarning: Columns (1,5,7,16,......) have mixed types. Specify dtype option on import or set l...
RuntimeWarning:numpy.dtype大小已更改,可能表明二进制不兼容(import numpy could not be resolved)
我尝试加载已保存的SVM模型时遇到此错误。我尝试卸载sklearn,NumPy和SciPy,然后再次重新安装最新版本(使用pip)。我仍然收到此错误。为什么?
In [1]: import sklearn; print sklearn.__version__
0.18.1
In [3]: import numpy; print numpy.__version__
1.11.2
In [5]: import scipy; print scipy.__version__
0.18.1
In [7]: import pandas; print pandas.__version__
0.19.1
In [10]: clf = joblib.load('model/trained_model.pkl')
---------------------------------------------------------------------------
RuntimeWarning Traceback (most recent call last)
<ipython-input-10-5e5db1331757> in <module>()
----> 1 clf = joblib.load('sentiment_classification/model/trained_model.pkl')
/usr/local/lib/python2.7/dist-packages/sklearn/externals/joblib/numpy_pickle.pyc in load(filename,mmap_mode)
573 return load_compatibility(fobj)
574
--> 575 obj = _unpickle(fobj,filename,mmap_mode)
576
577 return obj
/usr/local/lib/python2.7/dist-packages/sklearn/externals/joblib/numpy_pickle.pyc in _unpickle(fobj,mmap_mode)
505 obj = None
506 try:
--> 507 obj = unpickler.load()
508 if unpickler.compat_mode:
509 warnings.warn("The file '%s' has been generated with a "
/usr/lib/python2.7/pickle.pyc in load(self)
862 while 1:
863 key = read(1)
--> 864 dispatch[key](self)
865 except _Stop,stopinst:
866 return stopinst.value
/usr/lib/python2.7/pickle.pyc in load_global(self)
1094 module = self.readline()[:-1]
1095 name = self.readline()[:-1]
-> 1096 klass = self.find_class(module,name)
1097 self.append(klass)
1098 dispatch[GLOBAL] = load_global
/usr/lib/python2.7/pickle.pyc in find_class(self,module,name)
1128 def find_class(self,name):
1129 # Subclasses may override this
-> 1130 __import__(module)
1131 mod = sys.modules[module]
1132 klass = getattr(mod,name)
/usr/local/lib/python2.7/dist-packages/sklearn/svm/__init__.py in <module>()
11 # License: BSD 3 clause (C) INRIA 2010
12
---> 13 from .classes import SVC,NuSVC,SVR,NuSVR,OneClassSVM,LinearSVC,\
14 LinearSVR
15 from .bounds import l1_min_c
/usr/local/lib/python2.7/dist-packages/sklearn/svm/classes.py in <module>()
2 import numpy as np
3
----> 4 from .base import _fit_liblinear,BaseSVC,BaseLibSVM
5 from ..base import BaseEstimator,RegressorMixin
6 from ..linear_model.base import LinearClassifierMixin,SparseCoefMixin,\
/usr/local/lib/python2.7/dist-packages/sklearn/svm/base.py in <module>()
6 from abc import ABCMeta,abstractmethod
7
----> 8 from . import libsvm,liblinear
9 from . import libsvm_sparse
10 from ..base import BaseEstimator,ClassifierMixin
__init__.pxd in init sklearn.svm.libsvm (sklearn/svm/libsvm.c:10207)()
RuntimeWarning: numpy.dtype size changed,may indicate binary incompatibility. Expected 96,got 80
更新: 确定,请按照此处和
pip uninstall -y scipy scikit-learn
pip install --no-binary scipy scikit-learn
该错误现在消失了,尽管我仍然不知道为什么会首先发生该错误…
Asyncio如何修复sys:1:RuntimeWarning:从未等待协程'xxx'
如何解决Asyncio如何修复sys:1:RuntimeWarning:从未等待协程''xxx''?
构建一个刮板以异步刮刮多个页面。我创建了一个类,但是一旦我想运行测试方法,就会收到2个错误:
TypeError: ''coroutine'' object is not callable
sys:1: RuntimeWarning: coroutine ''Scraper.page'' was never awaited
这是我的代码:
from requests_html import AsyncHTMLSession
class Scraper(AsyncHTMLSession):
def __init__(self):
AsyncHTMLSession.__init__(self)
async def page(self):
t = await self.get("https://www.somePage.pl/strona/1/")
if __name__ == "__main__":
t = Scraper()
d1 = t.run(t.page())
print(d1.result)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
c – warning:返回类型默认为’int'[-Wreturn-type]
#include <stdio.h> main() { float c,d; c = 10215.3; d = c / 3; printf("%3.2f\n",d); return 0; }
它使用我编写的makefile编译:
cc -Wall -g printf.c -o printf
但我得到这个警告:
printf.c:2:1: warning: return type defaults to ‘int’ [-Wreturn-type]
它编译代码,并获得所需的输出,但我想了解这是什么意思
解决方法
main()
应该
int main()
在C89中,默认返回类型被假定为int,这就是为什么它的工作原理.
Django:RunTimeWarning:DateTimeField在时区支持处于活动状态时收到了一个简单的日期时间
我正在尝试测试基于Django购物车的购物车创建
但是当我尝试创建购物车时出现此错误:
RunTimeWarning:时区支持处于活动状态时,DateTimeField接收的是原始日期时间
我做了一些研究,但无法解决我的问题 datetime.datetime.now()
我的测试目录中的test_views.py:
from django.test import TestCase, Client, RequestFactoryimport unittestfrom django.contrib.auth.models import User, AnonymousUserfrom front.models import Entreprise, Cart, CartItemsfrom decimal import Decimalfrom front.cart import modelsimport datetimeimport pytzfrom pytz import all_timezonesfrom django.utils import timezonedef _create_cart_in_database(self, creationDate=datetime.datetime.now(), checkedOutDate=True): """ Helper function so I don''t repeat myself """ cart = models.Cart() cart.creationDate = creationDate cart.checkedOutDate = False cart.save() return cartdef test_cart_creation(self): creationDate = datetime.datetime.now() cart = self._create_cart_in_database(creationDate) id = cart.id cart_from_database = models.Cart.objects.get(pk=id) self.assertEquals(cart, cart_from_database)
models.py:
class Cart(models.Model): creationDate = models.DateTimeField()
我也有USE_TZ = True
自己的设置。
我试过了timezone.now()
但是还是不行:
def _create_cart_in_database(self, creationDate=timezone.now(), checkedOutDate=True):def test_cart_creation(self): creationDate = timezone.now()
RunTimeWarning:时区支持处于活动状态时,DateTimeField
Cart.creationDate收到的日期时间很短(2016-06-03 08:46:34.829000)。
编辑:
我现在有此错误,看来日期时间格式有误?
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) File "C:\Python27\lib\site-packages\django-1.9.5-py2.7.egg\django\db\models\base.py", line 820, in _save_table result = self._do_insert(cls._base_manager, using, fields, update_pk, raw) File "C:\Python27\lib\site-packages\django-1.9.5-py2.7.egg\django\db\models\base.py", line 859, in _do_insert using=using, raw=raw) File "C:\Python27\lib\site-packages\django-1.9.5-py2.7.egg\django\db\models\manager.py", line 122, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "C:\Python27\lib\site-packages\django-1.9.5-py2.7.egg\django\db\models\query.py", line 1039, in _insert return query.get_compiler(using=using).execute_sql(return_id) File "C:\Python27\lib\site-packages\django-1.9.5-py2.7.egg\django\db\models\sql\compiler.py", line 1059, in execute_sql for sql, params in self.as_sql(): File "C:\Python27\lib\site-packages\django-1.9.5-py2.7.egg\django\db\models\sql\compiler.py", line 1019, in as_sql for obj in self.query.objs File "C:\Python27\lib\site-packages\django-1.9.5-py2.7.egg\django\db\models\sql\compiler.py", line 958, in prepare_value value = field.get_db_prep_save(value, connection=self.connection) File "C:\Python27\lib\site-packages\django-1.9.5-py2.7.egg\django\db\models\fields\__init__.py", line 728, in get_db_prep_save prepared=False) File "C:\Python27\lib\site-packages\django-1.9.5-py2.7.egg\django\db\models\fields\__init__.py", line 1461, in get_db_prep_value value = self.get_prep_value(value) File "C:\Python27\lib\site-packages\django-1.9.5-py2.7.egg\django\db\models\fields\__init__.py", line 1440, in get_prep_value value = super(DateTimeField, self).get_prep_value(value) File "C:\Python27\lib\site-packages\django-1.9.5-py2.7.egg\django\db\models\fields\__init__.py", line 1296, in get_prep_value return self.to_python(value) File "C:\Python27\lib\site-packages\django-1.9.5-py2.7.egg\django\db\models\fields\__init__.py", line 1399, in to_python parsed = parse_datetime(value) File "C:\Python27\lib\site-packages\django-1.9.5-py2.7.egg\django\utils\dateparse.py", line 93, in parse_datetime match = datetime_re.match(value)TypeError: expected string or buffer
答案1
小编典典下面的代码行创建了一个简单的(非时区感知)日期时间:
creationDate = datetime.datetime.now()
尝试将该行更改为:
creationDate = timezone.now()
不要忘记timezone
在代码的开头导入:
from django.utils import timezone
DtypeWarning: Columns (1,5,7,16,......) have mixed types. Specify dtype option on import or set l...
DtypeWarning: Columns (1,5,7,16,......) have mixed types. Specify dtype option on import or set low_memory=False.
意思就是:列1,5,7,16....的数据类型不一样。
调试进去看了看,发现pandas在读取的时候确实把同一列数据中同一
个数值识别为不同的类型,比如:2000行第3列值为0的数据识别为Int类型,
而在4000行第3列值为0的数据识别为str类型。
两种解决方法:
# 1.设置read_csv的dtype参数,指定字段的数据类型
pd.read_csv(sio, dtype={"user_id": int, "username": object})
# 2.设置read_csv的low_memory参数为False
pd.read_csv(sio, low_memory=False})
注:low_memory
另外pandas对数据的类型是完全靠猜的,所以pandas每读取一块数据就对csv字段的数据类型进行猜一次,所以有可能pandas在读取不同块时对同一字段的数据类型猜测结果不一致。
low_memory=False 参数设置后,pandas会一次性读取csv中的所有数据,然后对字段的数据类型进行唯一的一次猜测。这样就不会导致同一字段的Mixed types问题了。
但是这种方式真的非常不好,一旦csv文件过大,就会内存溢出;所以推荐用第1中解决方案。
关于RuntimeWarning:numpy.dtype大小已更改,可能表明二进制不兼容和import numpy could not be resolved的介绍已经告一段落,感谢您的耐心阅读,如果想了解更多关于Asyncio如何修复sys:1:RuntimeWarning:从未等待协程'xxx'、c – warning:返回类型默认为’int'[-Wreturn-type]、Django:RunTimeWarning:DateTimeField在时区支持处于活动状态时收到了一个简单的日期时间、DtypeWarning: Columns (1,5,7,16,......) have mixed types. Specify dtype option on import or set l...的相关信息,请在本站寻找。
本文标签: