Centos 6.6,python 2.7.2对象没有属性'StringIO(Centos 6.6, python 2.7.2 object has no attribute 'StringIO)
我正在尝试在docker容器中运行我的python测试。 这是使用CentsOS 6.6安装python .2.7.2的Dockerfile的一部分:
RUN cd /tmp && \ wget https://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz && \ tar xvfz Python-2.7.2.tgz && \ cd Python-2.7.2 && \ ./configure --prefix=/usr/local && \ make && \ make altinstall RUN ln -s /usr/local/bin/python2.7 /usr/local/bin/python RUN wget https://bootstrap.pypa.io/ez_setup.py -O - | /usr/local/bin/python2.7 RUN /usr/local/bin/easy_install-2.7 pip RUN pip install python-gflags sqlparse pyyaml requests HTTPretty
在docker容器中运行我的测试时出现异常:
import io # some code here... buf = io.StringIO(data) AttributeError: 'module' object has no attribute 'StringIO'
在本地或服务器环境中运行测试时,我不会遇到此异常。
我试图在docker容器中执行简单的脚本:
import io print io.StringIO(None)
工作正常。 我很困惑。 这可能是什么问题?
@Blckknght,你是对的,代码有名为io的模块:
io.__file__ ::: /root/containerfolder/proejct/py/src/common/io.pyc
。 但我只能在码头工具中重现它。 当我将代码复制粘贴到服务器或在本地运行时,我说得对
io.__file__ ::: /opt/py/ext/python-2.7.2/lib/python2.7/io.pyc
什么是修复它的正确方法exept重命名模块:)?
回答:
- @Blckknght是对的,有一个名为“IO”(!!!大写!!!)的代码模块隐藏了内置的“io”
- 我的“本地”MacOS FS不区分大小写,但保留大小写,它区分io和IO,这就是为什么我在本地获得正确的“io”。
- 服务器具有区分大小写的FS
- Docker镜像具有不区分大小写的FS。 这就是它失败的原因。
这是一个很好的挑战,谢谢:)
I'm trying to run my python tests inside docker container. Here is a part of Dockerfile that installs python .2.7.2 using CentsOS 6.6:
RUN cd /tmp && \ wget https://www.python.org/ftp/python/2.7.2/Python-2.7.2.tgz && \ tar xvfz Python-2.7.2.tgz && \ cd Python-2.7.2 && \ ./configure --prefix=/usr/local && \ make && \ make altinstall RUN ln -s /usr/local/bin/python2.7 /usr/local/bin/python RUN wget https://bootstrap.pypa.io/ez_setup.py -O - | /usr/local/bin/python2.7 RUN /usr/local/bin/easy_install-2.7 pip RUN pip install python-gflags sqlparse pyyaml requests HTTPretty
I get an exception while running my tests inside docker container:
import io # some code here... buf = io.StringIO(data) AttributeError: 'module' object has no attribute 'StringIO'
I don't get this exception while running tests locally or on server env.
I tried to execute simple script in docker container:
import io print io.StringIO(None)
Works fine. I'm confused. What could be the problem here?
@Blckknght, you are right, code has module named io:
io.__file__ ::: /root/containerfolder/proejct/py/src/common/io.pyc
. But I can reproduce it only in docker. When I copy-paste code to server or run it locally, I'm getting right
io.__file__ ::: /opt/py/ext/python-2.7.2/lib/python2.7/io.pyc
What is the right way to fix it exept renaming the module :) ?
ANSWER:
- @Blckknght is right, there is a code module named "IO" (!!!uppercase!!!) that hides built-in "io"
- My "local" MacOS FS is case insensitive, but case preserving, it distinguishes io and IO, that is why I'm getting correct "io" locally.
- Server has case-sensitive FS
- Docker image has case insensitive FS. That is why it fails only there.
It was nice challenge, thanks :)
原文:https://stackoverflow.com/questions/33927071
最满意答案
这是在此问题中向团队报告的编译器错误: 使用来自不同程序集的参数内运算符 。 看起来修复是在master中,但我可以确认该问题仍然存在于15.5.6中。
This is a compiler bug that has been reported to the team in this issue: Use in-parameter operator from different assembly. It looks like the fix is in master, but I can confirm that the issue still exists in 15.5.6.
相关问答
更多-
进入重载<<运算符函数的对象必须是常量吗?(Do objects Coming into the Overloaded << Operator Function have to be Constants?)[2023-06-23]
我想到了。 我没有尝试更改进入的const对象,而是将其转换为存储在ostream变量Out中的。 ostream & operator<< (ostream &Out, const MyFloat & x) { int Counter=0; int PrintDigits=0; Out << "0."; if (x.NumberOfDigits != '0') { for (int i=x.MAXDIGIT-1; i>=0 && x.Number ... -
您的getter函数未标记为const,因此无法在常量对象上调用: inline ushort GetX() const { return m_nX; } ^^^^^ 如果没有const关键字,编译器必须假定该函数可能会修改对象,因此无法在常量对象上调用。 值得注意的是,在某些情况下,您可能需要const和非const版本,具有不同的返回类型,例如: const_iterator vector
::begin() const; //const version ... -
1.您正在将m_pString的元素与m_pString的长度进行right.m_pString 。 比较逻辑似乎错了。 bool MyString::operator==(const MyString &right) const { if (strlen(m_pString) != strlen(right.m_pString)) { return false; } for (size_t i = 0; i < strlen(m_pString); ++i ...
-
最简单和最清晰的方法是取消引用指针: (*j)(); 或者,您可以使用->语法和函数的名称(它是operator() ): j->operator()(); The easiest and clearest way is to dereference the pointer: (*j)(); Alternatively, you can use the -> syntax with the function's name (which is operator()): j->operator()();
-
我在gcc buglist上发布了这个,因为我觉得这是一个bug或至少在C ++参考中有歧义。 Jonathan Wakely提出了一个非常简单的解决方案: template
friend F &operator << (F &in, float f) { in.type ("f"); in.m_buf.str (""); using std::operator <<; // indicate proper operator in the next lin ... -
F#不允许您仅通过添加let bound函数来定义重载。 F#支持标准.NET实例或静态成员重载,因此在这种情况下,您需要添加一个静态成员: type Matrix = static member (*) (matrix : Matrix) (vector : IVector) = .. 注意:我建议您不要使用矩阵和向量之间的重载进行此类设计。 如果你继续以这种方式定义重载,我的意思是在混合类型之间,重载决策可能会变得模棱两可。 最好只在矩阵之间定义重载,然后在向量之间定义另一个集合。 然后你可以定义 ...
-
重载重载运算符(Overloading overloaded operators)[2023-05-29]
您所看到的行为是由const正确性引起的。 在类中定义的operator <<是非const的,因此它只能在非const对象或引用上操作,例如obj。 类外的非成员版本有两个常量操作数。 如果您将成员版本作为非成员编写,它将如下所示: binaryOperators operator<< (binaryOperators &left, const binaryOperators &right) { cout << "\nTwo"; return left; } 当重载匹配时,编译器选择最佳 ... -
我不知道你正在使用哪种语言,但它看起来有点像C ++,所以这是一个例子: class Rect { public: int x, y; int w, h; int right, bottom; // This method is called a constructor. // It allows you to perform tasks on // the instantiation of an ob ...
-
我可以在重载的struct运算符中使用常量参数吗?(Can I use constant parameters in overloaded struct operators?)[2023-11-26]
这是在此问题中向团队报告的编译器错误: 使用来自不同程序集的参数内运算符 。 看起来修复是在master中,但我可以确认该问题仍然存在于15.5.6中。 This is a compiler bug that has been reported to the team in this issue: Use in-parameter operator from different assembly. It looks like the fix is in master, but I can confirm t ... -
有时使用重载运算符(Using overloaded operators on times)[2023-05-03]
测试重载运算符没有什么特别之处。 只需在main中创建两个对象并编写如下内容: Time t1(10,20,30),t2(1,2,3); 现在,为了检查+ =运算符,写: t1+=10; 您的重载函数将自动调用,您还可以添加2个对象而不是数字,如下所示: t1+=t2; 唯一的区别是参数,而不是int,它将是Time类型的对象。 要检查<<运算符,只需写: cout<相关文章
更多- CentOS 6.6下Hadoop 1.0.3集群配置
- CentOS 6.6下Hadoop 1.0.3单节点配置
- 探索 Python,第 1 部分: Python 的内置数值类型
- 《JAVA代码规范》(十)成员函数和方法标准 (6.1-6.6)
- python2和python3的区别
- Python内建函数(G)
- Python资源索引 【转载】
- 【第六章】 AOP 之 6.6 通知参数 ——跟我学spring3
- Python内建函数(H)
- 【转帖】Python 资源索引
最新问答
更多- 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
- 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
- OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
- 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
- codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
- 在计算机拍照在哪里进入
- 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
- No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
- 单页应用程序:页面重新加载(Single Page Application: page reload)
- 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
- System.StackOverflow错误(System.StackOverflow error)
- KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
- 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
- android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
- TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
- 企业安全培训的各项内容
- 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
- C#类名中允许哪些字符?(What characters are allowed in C# class name?)
- NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
- 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
- 将多个行和可变行移动到列(moving multiple and variable rows to columns)
- 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
- 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
- Angular $资源不会改变方法(Angular $resource doesn't change method)
- 在Angular 5中不是一个函数(is not a function in Angular 5)
- 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
- 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
- 常见的python rpc和cli接口(Common python rpc and cli interface)
- Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
- 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)