python datetime模块离线安装_Python ImportError:没有名为datetime的模块(Python ImportError: No module named datetim...

Python ImportError:没有名为datetime的模块(Python ImportError: No module named datetime)

您好,我在尝试简单的日期时间导入时收到错误。

ImportError:没有名为datetime的模块

我在git控制台中尝试以下代码。

>>> from datetime.datetime import strptime

我尝试重新安装python,它似乎不起作用。 我究竟做错了什么?

Hi am getting an error while trying a simple datetime import.

ImportError: No module named datetime

I am trying the following code in the git console.

>>> from datetime.datetime import strptime

I have tried re-installing python and it doesn't seem to work. What am I doing wrong?

原文:https://stackoverflow.com/questions/21347346

2020-07-07 08:07

满意答案

datetime.datetime是模块datetime内的类datetime 。 您无法导入类的方法,这实际上是您要执行的操作。 相反,你可以:

from datetime import datetime

datetime.strptime(...)

或者以你想要的方式“提取”方法:

strptime = datetime.strptime

虽然=左侧的名字完全取决于你。

错误消息本身来自datetime中的第二个datetime时间,而不是第一个datetime.datetime 。

datetime.datetime is a class datetime inside a module datetime. You can't import a method of a class, which is effectively what you are trying to do. Instead, you can:

from datetime import datetime

datetime.strptime(...)

or to "extract" the method the way you seem to want it:

strptime = datetime.strptime

though the name on the left side of the = is completely up to you.

The error message itself is coming from the second datetime in datetime.datetime, not the first.

2016-09-09

相关问答

当我创建了一个virtualenv,然后从12.04升级到14.04时,这发生在我身上。 我不得不删除我的virtualenv并重新创建它,并且在完成之后,所有事情都再次奏效。 This happened to me when I created a virtualenv and then upgraded from 12.04 to 14.04. I had to delete my virtualenv and recreate it, and after doing that, everyt...

您对sys.path修改假定当前工作目录始终处于main/ 。 不是这种情况。 相反,只需将父目录添加到sys.path : import sys

import os.path

sys.path.append(os.path.join(os.path.dirname(__file__), '..'))

import gen_py.lib

不要忘记在gen_py和lib中包含一个文件__init__.py - 否则,它们将不被识别为Python模块。 Your modification of s...

回溯表明问题出在特定的导入中。 您可以从命令行验证这一点。 比如在我的机器上,我得到了 $ python -c 'from terms.items import TermsItem'

Traceback (most recent call last):

File "", line 1, in

ImportError: No module named terms.items

看看你的文件夹层次结构,我看不到所谓的“术语”模块,所以这可能是你所缺少的但是因为你指...

确保您的文件夹测试包含__init__.py 下面的代码将项目project的路径附加到test.py sys.path python将遍历搜索项目中的模块和文件 import sys

sys.path.append("/path/to/project")

from app.stamp import Timestamp

make sure your folder tests contains __init__.py Below code appends the path of your proj...

你需要在core目录中有一个__init__.py文件:这使它成为一个包,这意味着你可以使用“dotted”语法core.text访问子模块。 __init__.py文件可以为空。 参考: http : //docs.python.org/3.3/tutorial/modules.html#packages You need to have a __init__.py file inside the core directory: this makes it a package, meaning ...

找到了解决办法。 我通过pip卸载googlemaps,然后使用easy_install重新安装。 显然OSX不喜欢点子。 Found a fix. I uninstalled googlemaps via pip and then reinstalled using easy_install. Apparently OSX doesn't like pip.

您应该在您的apps目录中添加__init__.py ├──apps

├──__init__.py

│ ├── app1

| | ├── __init__.py

| | └── ...

│ └── app2

| ├── __init__.py

| └── ...

You should add __init__.py inside your apps directory ├──app...

第一:你在上面的行中导入了twython。 第20行尝试再次导入twython但是已经导入的twython包。 它在twython中找不到它。 我会摆脱第19行。 第二:第20行应该from twython import Twython读取from twython import Twython一个是包(twython),一个是类(Twython)。 First: You imported twython in the line above. Line 20 is trying to import ...

基于跟进谷歌支持团队已经发现,不推荐使用google-cloud-datastore与datastore进行通信,而是使用ndb进行数据存储通信。 此处记录了使用客户端数据存储库声明弃用的更新文档 这里记录了在python中开始使用ndb客户端库的文档 Based on follow up with google support team have figured out that communicating with datastore using google-cloud-datastore ...

datetime.datetime是模块datetime内的类datetime 。 您无法导入类的方法,这实际上是您要执行的操作。 相反,你可以: from datetime import datetime

datetime.strptime(...)

或者以你想要的方式“提取”方法: strptime = datetime.strptime

虽然=左侧的名字完全取决于你。 错误消息本身来自datetime中的第二个datetime时间,而不是第一个datetime.datetime 。 da...

相关文章

如果出现如下错误: >>> import sqlite3 Traceback (mo

...

mod_python: the long story - Grisha Trubetskoy

...

python2和python3的区别,1.性能 Py3.0运行 pystone benchmark的速

...

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值