-
0 votesanswersviews
如何导入discord bot对象以便在其他模块中使用
我试图减少我的discord bot的主文件中的行数,所以我创建了一个模块来处理某些命令,问题是我必须将bot对象传递给模块中主文件外的每个函数,这个增加我传递给每个函数的变量数量,它变得非常混乱 . 在下面的示例中,KsBot.py是我的主要bot文件,BasicCommand.py是我编写简单命令并将其导入KsBot.py以供使用的地方,KsBot是bot对象 在KsBot.py中: if m... -
2 votesanswersviews
使用子模块[discord.py]中的命令与后台任务交互
我有一个用非重写版本的discord.py写的Discord bot,它发送一个类似心跳的消息(除其他外) . 我不知道我是否理解正确但是从测试中我发现我需要在 main.py 文件中使用 async def heartbeat() 函数 . 摘自 main.py (心跳按预期工作): [...] import asyncio import datetime from configparser i... -
0 votesanswersviews
使用scipy时找不到模块
我最近正确安装了numpy和scipy . 以下行运行没有错误 . 导入scipy 我在使用scipy.io.wavefile时遇到了困难 . 我一直在尝试使用"best answer"的"best answer"中的代码 . 但是,当我尝试第一行时, from scipy.io import wavfile 我收到以下错误和追溯, Traceback... -
816 votesanswersviews
从不同的文件夹导入文件
我有以下文件夹结构 . application/app/folder/file.py 我想从 file.py 导入一些驻留在其中的Python文件中的函数 application/app2/some_folder/some_file.py 我试过了 from application.app.folder.file import func_name 和其他一些尝试,但到目前为止我无法正确导入 . 我... -
369 votesanswersviews
ImportError:没有名为requests的模块
每当我尝试导入requests时,我都会收到错误说 No module Named requests . import requests 我得到的错误: File "ex2.py", line 1, in <module> import requests ImportError: No module named requests -
657 votesanswersviews
如何卸载(重新加载)Python模块?
我有一个长期运行的Python服务器,并希望能够在不重新启动服务器的情况下升级服务 . 这样做的最佳方法是什么? if foo.py has changed: unimport foo <-- How do I do this? import foo myfoo = foo.Foo() -
335 votesanswersviews
Python错误“ImportError:没有命名的模块”
Python安装在本地目录中 . 我的目录树如下所示: (local directory)/site-packages/toolkit/interface.py 我的代码在这里: (local directory)/site-packages/toolkit/examples/mountain.py 为了运行这个例子,我写了 python mountain.py ,在我的代码中: from t... -
7 votesanswersviews
ImportError:无法导入名称urlopen
我正在尝试为我的项目打开一个URL,这是我的代码: from urllib2 import urlopen page = urlopen("https://docs.python.org/3/howto/urllib2.html") contents = page.read() 这只是一个简单的演示代码,但是当我运行代码时,我收到以下错误 "ImportError ... -
425 votesanswersviews
从父文件夹导入模块
我正在运行Python 2.5 . 这是我的文件夹树: ptdraft/ nib.py simulations/ life/ life.py (我在每个文件夹中也有 __init__.py ,为了便于阅读,这里省略了) 如何从 life 模块中导入 nib 模块?我希望有可能不用修补sys.path . 注意:正在运行的主模块位于 ptdraft 文件夹中 . -
0 votesanswersviews
在Mac上导入shell中的模块
我最近开始阅读第四版Mark Lutz的书“学习Python” . 我下载了最新版本的Python(v3.7)和IDLE,我在Mac上运行 . 我在尝试导入模块时遇到问题 . 在页54,它说使用以下代码创建一个脚本threenames.py: a = 'dead' b = 'parrot' c = 'sketch' 我把它保存在我的桌面上 . 接下来我打开一个shell: import th... -
456 votesanswersviews
如何在Python中进行相对导入?
想象一下这个目录结构: app/ __init__.py sub1/ __init__.py mod1.py sub2/ __init__.py mod2.py 我正在编码 mod1 ,我需要从 mod2 导入一些东西 . 我该怎么办? 我试过 from ..sub2 import mod2 但是我得到了"Attempt... -
1 votesanswersviews
导入python模块时如何解决KeyError?
我试图从不同的目录级别导入模块,所以我使用: import os import sys sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) 但现在我得到了这个错误 . 我正在使用Spyder,并且我第一次使用以下导入,它工作正常 . from source.searc... -
0 votesanswersviews
在Python 3.5.3中导入tensorflow的问题
当我在 Python 3.5.3 中导入tensorflow时,它给了我以下内容: 错误: 没有名为_pywrap_tensorflow的模块除非您使用的是bazel,否则不应尝试从其源目录导入tensorflow;请退出tensorflow源树,然后从那里重新启动你的python解释器 . 我使用以下命令安装了 tensorflow-0.12.0 : python -m pip insta... -
8 votesanswersviews
无法在Python3中导入sqlite3
我无法在Python 3.5.0版本中导入sqlite3模块 . 这是我得到的: >>> import sqlite3 Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.... -
439 votesanswersviews
如何在同一目录或子目录中导入该类?
我有一个存储所有 .py 文件的目录 . bin/ main.py user.py # where class User resides dir.py # where class Dir resides 我想在 main.py 中使用 user.py 和 dir.py 中的类 .如何将这些Python类导入 main.py ?此外,如果 user.py 在子目录中,如何导入类 ... -
0 votesanswersviews
从PyCharm运行python脚本 . 在Pycharm中导入
似乎Pycharm 1.5.3有些神奇,或者我错过了一些东西 . 我有以下文件结构: /sp /sp/tools.py /sp/test/main.py 文件包含以下代码 main.py: __author__ = 'username' import tools import sys def test1(): print locals() print globals() ... -
70 votesanswersviews
用于相对进口的python包装
首先关闭所有:对不起,我知道有很多关于相关进口的问题,但我没有找到解决方案 . 如果可能,我想使用以下目录布局: myClass/ __init__.py test/ demo.py benchmark.py specs.py src/ __init__.py myClass.py 现在我的问... -
0 votesanswersviews
安装后无法在PyCharm(Jupyter)中导入Xgboost包
我使用Pycharm(2017.3.5)作为我的Python(3.6)IDE,我集成了Jupyter笔记本进行开发 . 直到现在,我没有安装新软件包的问题,我使用Pycharm做了 . 今天我正在努力学习名为xgboost的机器学习库 . 首先,安装错误是我需要更新pip . 我从版本9.7到10.1做了它 . 然后安装成功如下: 即使在“包安装成功”之后,它也没有在包列表中列出(我也尝试... -
0 votesanswersviews
ImportError:没有名为django_baker的模块
我在macOS上安装了pip by sudo pip install django-baker. 的django-baker . 该模块可以在/Library/Python/2.7/site-packages中找到,但是我无法导入这个包 . 我试过了 sudo chmod -R go+rX /Library/Python/2.7/site-packages ,但没有效果 . 路径或安装有问题吗?... -
1 votesanswersviews
Python:将文件从day_one.py导入main.py然后在day_one中导入一个函数从main.py.错误无法导入
我不确定为什么它不起作用,这可能是一个你无法解决的问题,但我想知道为什么它不起作用 . 我很抱歉,如果我浪费你的时间,或者没有正确地提出这个问题,我已经16岁了,也是Python的新手 . 在main.py中 来自day_one import day_one_def 在day_one.py中 从主要导入main_home_window 错误消息 ImportError:无法导入名称'day_o... -
458 votesanswersviews
Python中的相对导入3
我想从同一目录中的另一个文件导入一个函数 . 有时它适用于我 from .mymodule import myfunction 但有时我会得到: SystemError: Parent module '' not loaded, cannot perform relative import 有时它适用于 from mymodule import myfunction ,但有时我也会得到: Sys... -
399 votesanswersviews
如何根据名称导入模块?
我正在编写一个Python应用程序,它将命令作为参数,例如: $ python myapp.py command1 我希望应用程序是可扩展的,即能够添加实现新命令的新模块,而无需更改主应用程序源 . 树看起来像: myapp/ __init__.py commands/ __init__.py command1.py command... -
173 votesanswersviews
django import error - 没有名为core.management的模块
好的,我看到很多这些错误 . 我已经尝试过我所知道的所有事情并且尚未弄清楚这一点 . 我正在开发运行python 2.5和Django 1.3的开发服务器 . 在解压缩tar.gz下载后,使用python setup.py install安装了Django 1.3 . 一切正常,我很少需要运行 manage.py 但我正在尝试使用新的静态文件应用程序并遇到问题 . python manage.py... -
837 votesanswersviews
给定完整路径如何导入模块?
如何在完整路径下加载Python模块?请注意,该文件可以位于文件系统中的任何位置,因为它是一个配置选项 . -
711 votesanswersviews
从相对路径导入模块
如何根据相对路径导入Python模块? 例如,如果 dirFoo 包含 Foo.py 和 dirBar ,而 dirBar 包含 Bar.py ,如何将 Bar.py 导入 Foo.py ? 这是一个直观的表示: dirFoo\ Foo.py dirBar\ Bar.py Foo 希望包含 Bar ,但重组文件夹层次结构不是一种选择 . -
0 votesanswersviews
PythonAnywhere计划任务导入错误
我想每小时向我的用户发送推送通知 . from push_notifications.models import APNSDevice print('test schedule task') device = APNSDevice.objects.all() if device is None: print('None Device') print('number of models is... -
1 votesanswersviews
导入LXML时出错
我正在导入“来自docx导入文档” . 这给了一个错误 文件“”,第1行,在文件“/usr/local/lib/python2.7/site-packages/docx.py”,第17行,来自lxml import etree ImportError:/ usr / local / lib / python2 . 7 / site-packages / lxml-3.7.0-py2.7-lin... -
0 votesanswersviews
无法在Mac上安装以下python库和软件包
我的Python程序: #!/usr/bin/python from pylab import plot,show from numpy import vstack,array from numpy.random import rand from scipy.cluster.vq import kmeans, vq, whiten import... -
2 votesanswersviews
ImportError:没有名为'_sqlite3'的模块
每当我导入sqlite3时,它都会导致导入错误 . 谁能告诉我如何为python3导入sqlite3 . 另外,我在我的vps上使用CentOS 6.5 . 回溯(最近一次调用最后一次):文件“", line 1, in File " /usr/local/lib/python3.5/sqlite3/ init .py ", line 23, in from sql... -
0 votesanswersviews
从多个egg文件导入单个命名空间下的包
我有多个鸡蛋文件需要添加到我的 sys.path . 所有这些文件都打包在 cmp 命名空间下 . 例如: 在 cmp 命名空间下有一个带有 tools 包的egg文件 cmp.tools-0.0.0-py2.7.egg ,我将其导入: sys.path.append('cmp.tools-0.0.0-py2.7.egg') import cmp.tools 另一个鸡蛋文件 cmp.entiti...