简体   繁体   English

区分大小写,带有python 2.7.15中模块和文件的名称

[英]Case sensitivity with names of modules and files in python 2.7.15

I have encountered a rather funny situation: I work in a big scientific collaboration whose major software package is based on C++ and python (2.7.15 still). 我遇到了一个相当有趣的情况:我在一个大型的科学合作中工作,其主要软件包基于C ++和python(仍为2.7.15)。 This collaboration also has multiple servers (SL6) to run the framework on. 该协作还具有多个服务器(SL6)以在其上运行框架。 Since I joined the collaboration recently, I received instructions on how to set up the software and run it. 自从我最近加入合作以来,我收到了有关如何设置和运行软件的说明。 All works perfectly on the server. 一切都能在服务器上完美运行。 Now, there are reasons not to connect to the server to do simple tasks or code development, instead it is preferrable to do these kind of things on your local laptop. 现在,有理由不连接到服务器来执行简单的任务或代码开发,而是最好在本地便携式计算机上执行这些操作。 Thus, I set up a virtual machine (docker) according to a recipe I received, installed a couple of things (fuse, cvmfs, docker images, etc.) and in this way managed to connect my MacBook (OSX 10.14.2) to the server where some of the libraries need to be sourced in order for the software to be compiled and run. 因此,我根据收到的食谱设置了一个虚拟机(docker),安装了几件东西(保险丝,cvmfs,docker映像等),并以此方式将MacBook(OSX 10.14.2)连接到需要提供某些库的服务器,以便编译和运行该软件。 And after 2h it does compile! 然后2小时后它会编译! So far so good.. 到现在为止还挺好..

Now comes the fun part: you run the software by executing a specific python script which is fed as argument another python script. 现在来了有趣的部分:您通过执行特定的python脚本来运行软件,该脚本作为参数提供给另一个python脚本。 Not funny yet. 还不有趣。 But somewhere in this big list of python scripts sourcing one another, there is a very simple task: 但是在这个庞大的python脚本清单中的某个地方,有一个彼此很简单的任务:

import logging
variable = logging.DEBUG

This is written inside a script that is called Logging.py. 这是在称为Logging.py的脚本中编写的。 So the script and library only are different by the first letter: l or L. On the server, this runs perfectly smooth. 因此,脚本和库仅以首字母不同:l或L。在服务器上,运行非常流畅。 On my local VM set up, I get the error 在我的本地VM设置上,出现错误

AttributeError: 'module' object has no attribute 'DEBUG' AttributeError:“模块”对象没有属性“ DEBUG”

I checked the python versions ( which python ) and the location of the logging library ( print logging.__file__ ), and in both set ups I get the same result for both commands. 我检查了python版本( which python )和日志记录库的位置( print logging.__file__ ),在这两个设置中,两个命令的结果相同。 So the same python version is run, and the same logging library is sourced but in one case there is a mix up with the name of the file that sources the library. 因此,将运行相同的python版本,并获取相同的日志记录库,但在一种情况下,源库的文件名会被混淆。

So I am wondering, if there is some "convention file" (like a .vimrc for vi) sourced somewhere where this issue could be resolved by setting some tolerance parameter to some other value...? 所以我想知道,是否有某个地方的“约定文件”(如vi的.vimrc)源自可以通过将一些公差参数设置为其他值来解决此问题的地方?

Thanks a lot for the help! 非常感谢您的帮助! conni conni

as others have said, OSX treats names as case-insensitive by default, so the Python bundled logging module will be confused with your Logging.py file. 正如其他人所说,OSX默认情况下将名称区分大小写,因此Python捆绑的logging模块将与您的Logging.py文件混淆。 I'd suggest the better fix would be to get the Logging.py file renamed, as this would improve compatibility of the code base. 我建议最好的解决方法是重命名Logging.py文件,因为这将提高代码库的兼容性。 otherwise, you could create a "Case-sensitive" APFS file system using "Disk Utility" 否则,您可以使用“磁盘工具”创建“区分大小写”的APFS文件系统

if you go with creating a file system, I'd suggest not changing the root/system partition to case-sensitive as this will break various programs in subtle ways. 如果您要创建文件系统,建议不要将根/系统分区更改为区分大小写,因为这将以微妙的方式破坏各种程序。 you could either repartition your disk and create a case-sensitive filesystem, or create an "Image" (this might be slower, not sure how much) and work in there. 您可以重新分区磁盘并创建区分大小写的文件系统,或者创建“映像”(这可能会比较慢,不确定多少)并在那里工作。 Just make sure you pick the "APFS (Case-sensitive)" format when creating the filesystem! 只需确保在创建文件系统时选择“ APFS(区分大小写)”格式即可!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM