草庐IT

Import-Package

全部标签

Python: `from x import *` 没有导入所有内容

我知道import*不好,但有时我懒得打字或记不住导入时,我会用它来快速制作原型(prototype)我正在尝试以下代码:fromOpenGL.GLimport*shaders.doSomething()它会导致错误:`NameError:globalname'shaders'isnotdefined'如果我更改导入:fromOpenGL.GLimport*fromOpenGL.GLimportshadersshaders.doSomething()错误消失。为什么*不包括shaders? 最佳答案 如果shaders是一个子模块并

python - Apache/mod_wsgi 中的 Django 部署问题。导入错误 : Could not import settings 'site.settings'

当我执行django-admin.pystartprojectsite它有效。但如果我只复制站点文件夹,它就不起作用。为什么?ServerNamedjango.stanislavfeldman.com#DjangosettingsWSGIScriptAlias//var/www/django/wsgi_handler.pyWSGIDaemonProcessdjango.stanislavfeldman.commaximum-requests=200stack-size=524288ErrorLog/var/www/django/error.logLogLevelwarnwsgi_han

python - "sys-package-mgr*: can' t 创建包缓存目录“当使用 Jython 运行 python 脚本时

我想用Jython运行Python脚本。结果显示正确,但同时出现警告信息,“sys-package-mgr*:can'tcreatepackagecachedir”我该如何解决这个问题?提前致谢~~~ 最佳答案 您可以在启动jython时通过设置“python.cachedir”选项将缓存目录的位置更改为您具有读写权限的位置,例如:jython-Dpython.cachedir=*yourcachedirdirectoryhere*或:java-jarmy_standalone_jython.jar-Dpython.cachedir

python - IPython 笔记本 - ShimWarning : The `IPython.kernel` package has been deprecated

我在将一些包导入IPython-Notebook时收到以下消息:%matplotlibnotebookimportnumpyasnpimportmatplotlibasmplimportmatplotlib.pyplotaspltfromscipy.integrateimportodeint//anaconda/lib/python3.4/site-packages/IPython/kernel/__init__.py:13:ShimWarning:The`IPython.kernel`packagehasbeendeprecated.Youshouldimportfromipyker

python - 为什么 "import module"和 "from module import * "中全局变量的行为不同?

让我们让a.py成为:deffoo():globalspamspam=42return'this'在控制台,如果我简单地导入,事情对我来说很有意义:>>>importa>>>a.foo()'this'>>>a.spam42但是,如果我做不太受欢迎的事情并且...>>>fromaimport*>>>foo()'this'>>>spamTraceback(mostrecentcalllast):File"",line1,inNameError:name'spam'isnotdefined>>>a.spamTraceback(mostrecentcalllast):File"",line1,

python - 将图像导入 python :cannot import name 'imread'

我是python的新手,我想导入图像。importnumpyasnpfromscipy.miscimportimread,imsave,imresize#ReadanJPEGimageintoanumpyarrayimg=imread('Cover.jpg')print(img.dtype,img.shape)但我遇到以下错误:无法导入名称“imread”我已经成功安装了numpy和scipy。 最佳答案 您还需要安装PIL(Pillow),因为scipy使用它来读取图像:pipinstallPillow注意fromthedocs:

python - django 1.9 中的 from django.views.generic.simple import direct_to_template 的等价物是什么

我想将我的主页设为index.html,它位于名为templates/caSTLe_tm/index.html的模板目录中,但url显示"nomodulenamedsimple".基于通用的View在django>1.4中被弃用。现在,如何将主页重定向到index.html网址.pyfromdjango.conf.urlsimporturl,patterns,includefromdjango.conf.urls.staticimportstaticfromdjango.confimportsettingsfromdjango.contribimportadminfromcastlei

android - E : unable to locate package pip

我一直在尝试搭建Python-android环境,一直收到这个错误信息:~$sudoapt-getinstallbuild-essentialpatchgit-coreccacheantpippython-devsudo:/var/lib/sudo/plaixwritablebynon-owner(040777),shouldbemode0700[sudo]passwordforplaix:Readingpackagelists...DoneBuildingdependencytreeReadingstateinformation...DoneE:Unabletolocatepacka

Python "import"作用域

我正在处理一些自动为我生成的python代码。我想避免手动编辑这些python文件,因此出现这个问题:foo.py:deffoo():print"foo"boo.py:defboo():foo.foo()#bar.py:importfooimportboodefbar():boo.boo()print"bar"执行:python.exebar.py给出了boo没有找到foo的错误。但是bar正在导入foo和boo。foo不应该自动提供给boo吗?有办法吗?如前所述,boo.py是自动为我生成的,我想避免将importfoo添加到boo.py。谢谢。 最佳答案

python - 导入错误 : Failed to import any qt binding, Python-Tensorflow

我正在开始我的Tensorflow冒险之旅。我认为我已正确安装所有内容,但在运行此代码时,PyCharm返回错误:Traceback(mostrecentcalllast):File"C:/Users/tymot/Desktop/myenv3/env/Tensorflow/all_good.py",line15,inimportmatplotlib.pyplotaspltFile"C:\Users\tymot\Anaconda1\lib\site-packages\matplotlib\pyplot.py",line115,in_backend_mod,new_figure_manag