【Python 之 包的导入】教程文章相关的互联网学习教程文章

使用selenium的unittest在python中运行完美,但在django manage.py测试中出现导入错误【代码】

我有这个文件,由Selenium IDE生成from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException import unittest, time, reclass Tcase(unittest.TestCase):def setUp(self):self.driver = webdriver.Firefox()self.driver.implicitly_wait(30)self.base_url = "http://localhost:9999/"self.ve...

python3.7导入unittest,默认执行不是unittest【图】

随笔。学习中发现Python3.7引入unittest框架,要去执行的时候发现不是unittest的,还是普通执行,运行的时候不报错,但是也看不到执行效果,如下图:执行的时候不报错,但是也没有执行结果,要去左上角新增unittest方式,选择Edit Configurations...然后去新增unittest执行方式然后把你要用unittest框架执行的脚本加进来,name随便起一个你记得的弄好应该就是这样了 点击Apply和OK之后,回到主页面,再run应该就可以了

python – 限制导入到特定路径,而不限制导入模块的路径【代码】

是否可以从特定目录导入模块,而不影响导入模块的导入路径? 如果我要将sys.path暂时替换为所需目录,则导入的模块将无法导入该目录之外的任何内容. 我不想只将sys.path添加到目录中,因为我不希望导入回退到另一个源.解决方法:标准库的imp module允许您搜索路径列表以查找和导入模块,而无需更改sys.path.例如:import impsearch_paths = [path_to_spam] modfile, modpath, description = imp.find_module('spam', search_paths) with...

在python中的zope.interface.registry中导入错误【代码】

我正在虚拟环境中安装项目.我收到了错误from zope.interface.registry import Components Traceback (most recent call last):File "<console>", line 1, in <module> ImportError: No module named registry该模块的版本为4.0.5>>> import pkg_resources >>> pkg_resources.get_distribution("zope.interface").version '4.0.5'我在我的机器上尝试了相同的操作(不是虚拟环境),>>> import pkg_resources >>> pkg_resources.get_dis...

python – Behave:如何从另一个文件导入步骤?【代码】

我刚开始使用behave,一个使用Gherkin syntax的Pythonic BDD框架.表现有一个特征,例如:Scenario: Calling the metadata APIGiven A matching serverWhen I call metadataThen metadata response is JSONAnd response status code is 200和步骤文件,例如:... @then('response status code is {expected_status_code}') def step_impl(context, expected_status_code):assert_equals(context.response.status_code, int(expected_st...

python – 无法导入名称get_user_model【代码】

我使用django-registrations,而我在admin.py中添加了这段代码from django.contrib import adminfrom customer.models import Customerfrom .models import UserProfilefrom django.contrib.auth.admin import UserAdminfrom django.contrib.auth import get_user_modelclass UserProfileInline(admin.StackedInline):model = UserProfilecan_delete = Falseclass UserProfileAdmin(UserAdmin):inlines=(UserProfileInline, )admin....

python – 将函数中的局部变量导入timeit【代码】

我需要计算跨越可变数据量的函数的执行时间.def foo(raw_data):preprocessed_data = preprocess_data(raw_data)time = timeit.Timer('module.expensive_func(preprocessed_data)', 'import module').timeit()但是,preprocessed_data不是全局变量.它不能从__main__导入.它是本子程序的本地. 如何将数据导入timeit.Timer环境?解决方法:将它传递给时间,而不是字符串. (不幸的是,这会引入一些额外的函数调用开销,因此只有当时间淹没那...

Python程序无法导入点解析器【代码】

我试图从命令行运行一个巨大的演化模拟python软件.该软件依赖于以下python包: 1-networkX 2- pyparsing 3 numpy的 4- pydot 5 matplotlib 6- graphviz的 我得到的错误是这样的:Couldn't import dot_parser, loading of dot files will not be possible. initializing with file= initAdapt.py in model dir= ./Test_adaptation// Traceback (most recent call last):File "run_evolution.py", line 230, in <module>gr.write_dot...

在python3中导入美丽的汤【代码】

我想在python3中导入beautifulsoup.我有这条线:from bs4 import BeautifulSoup它说:from bs4 import BeautifulSoup File "/usr/local/lib/python2.7/dist-packages/bs4/__init__.py", line 175 except Exception, e:^ SyntaxError: invalid syntax我看到它仍在尝试使用python2.7包.我已经使用pip3为python3安装了beautifulsoup,并在检查时发现包中有/usr/lib / python3 / dist-packages /.另外在检查sys.path时,我发现此路径存在...

python – ImportError:无法导入名称ProtocolError【代码】

最近我在使用pip时遇到了困难,每当我尝试发出pip命令时,我都会收到以下错误消息.File "/usr/bin/pip", line 9, in <module>load_entry_point('pip==1.5', 'console_scripts', 'pip2.7')()File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 353, in load_entry_pointreturn get_distribution(dist).load_entry_point(group, name)File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2302, in load_ent...

Python 模块的导入 day5【代码】

一、模块 1、标准模块python自带的 2、第三方模块需要自己安装的模块 3、自己写的python文件一个python文件,就是一个模块(1)导入模块的实质就是把你导入的模块运行了一遍(2) 查找模块的顺序a、在当前了目录下找b、在python环境变量里找import sys print( sys.path)#查找环境变量路径  导入其他路径下的python文件,使用append 或insert方法将路径加到环境变量里import sys sys.path.append(r/Users/smh/PycharmProjects/bestt...

python中的Turtle模块没有导入【代码】

这是我第一次在python中使用turtle模块,但我似乎无法导入它?这是我的代码:from turtle import *pen1 = Pen() pen2 = Pen()pen1.screen.bgcolour("#2928A7") 这是我得到的错误:Traceback (most recent call last):File "C:\Python34\Python saves\turtle.py", line 2, in <module>from turtle import *File "C:\Python34\Python saves\turtle.py", line 5, in <module>pen1 = Pen() NameError: name 'Pen' is not defined谁能告诉...

python – 导入CIFAR – 10数据集到R【代码】

我正在尝试下载CIFAR – 10图像数据集;http://www.cs.toronto.edu/~kriz/cifar.html 在R但我似乎无法提取文件.我已经尝试了所有三种格式.bin,.mat和python.任何人都可以帮助提出一些如何提取它们的建议吗? 非常感谢,Will解决方法:与任何事情一样,我认为最简单的方法通常是捎带别人的勤奋.对于这种情况,这意味着寻找已经转换过它的其他人.快速谷歌搜索呈现this site(其中包含图像的R数据文件)是该方法的一个很好的候选者. 或者,如...

Python并从excel文件导入浮点数【代码】

所以我有一个看起来像这样的excel文件Name R s l2 max_amplitude ref_amplitudeR_0.3_s_0.5_l2_0.1 0.3 0.5 0.1 1.45131445 1.45131445R_0.3_s_0.5_l2_0.6 0.3 0.5 0.6 3.52145743 3.52145743...R_1.1_s_2.0_l2_1.6 1.1 2.0 1.6 5.07415199 5.07415199R_1.1_s_2.0_l2_2.1 1.1 2.0 2.1 5.78820419 5.78820419R_1.1_s_2.0_l2_2.6 1.1 2.0 2.6 5.84488964 5.84488964R_1.1_s_2.0_l2_3.1 1.1 2.0 3.1 6.35387516 ...

在python中,您是否需要在每个拆分文件中导入模块?

我有一个python脚本变得相当长.因此,将相当大的单个脚本中定义的函数写入单个文件中,以便于维护并在不同的主脚本之间轻松共享. 在单个脚本中,我在文件顶部导入numpy和其他模块.现在,如果将函数写入单独的文件,我需要在该单独的文件中导入numpy.我宁愿避免这种情况,因为有了多个函数,它最终会导入几次numpy. 可以这样做吗?谢谢解决方法:是的,可以这样做,如下所述:Python: Importing an “import file” 简而言之,您可以将所有导入...