天道酬勤,学无止境

python-module

pytest module import ImportError: No module named

This question has been asked DOZENS of times before, but every one I've come across doesn't have any working solutions for me. I'm using Python 2.7 and pytest to run tests. Structure is as follows (from the root of my project/git repo): myapp/ myapp/ __init__.py # def main(): # ... stuff # if __name__ == "__main__": # main() __main__.py # import __init__ as myapp # myapp.main() config.yaml # (app config file) myapplib/ __init__.py # (Empty file) config.py # Loads {projectroot}/config.yaml # def cfg(): # ... stuff tests/ test_stuff.py # from myapplib.config import cfg I then try to run the

2022-01-18 00:57:38    分类:问答    python   python-2.7   pytest   python-module

cx_freeze 和导入模块(cx_freeze and importing modules)

问题 我想使用 cx_freeze 编译带有子模块的 Python 3.3 模块。 所以,我的目录结构是: projectname/ __init__.py submodule1/ __init__.py bootstrap.py script1.py submodule11/ script2.py submodule2/ ... 在__init__.py我导入 from submodule1 import bootstrap 并从引导程序中 import submodule1.submodule11.script2 如果我运行初始化文件,一切都很好,并且带有子模块导入的脚本会正确执行。 当我编译它时,我使用这个 setup.py: from cx_Freeze import setup,Executable import sys includes = [] excludes = ['Tkinter'] packages = ['submodule1', 'submodule2'] base = "Win32GUI" setup( name = 'myapp',version = '0.1',description = 'app',author = 'user', options = {'build_exe': {'excludes':excludes,'packages'

2022-01-16 14:52:50    分类:技术分享    python   compilation   executable   cx-freeze   python-module

cx_freeze and importing modules

I want to compile a Python 3.3 module with submodules using cx_freeze. So, my dir strucuture is: projectname/ __init__.py submodule1/ __init__.py bootstrap.py script1.py submodule11/ script2.py submodule2/ ... In the __init__.py I import from submodule1 import bootstrap and from the bootstrap import submodule1.submodule11.script2 If I run the init file, anything is good and the script with the submodule imports is executed correctly. When I compile it, I use this setup.py: from cx_Freeze import setup,Executable import sys includes = [] excludes = ['Tkinter'] packages = ['submodule1',

2022-01-16 10:33:08    分类:问答    python   compilation   executable   cx-freeze   python-module

使用 PIP 为用户安装 openpyxl(Using PIP to install openpyxl for a user)

问题 我编写了一个脚本,使用户能够自动填写他们的每周时间表并将其保存为新的 Excel 电子表格。 我以为我可以将 Openpyxl 文件夹与要导入的脚本放在同一目录中,但它似乎不起作用。 我已经根据下面的一些其他线程整理了一些代码,以便在导入之前检查 openpyxl。 所以我希望有能力设置openpyxl。 我打算在导入操作系统、系统、时间、日期时间等期间运行这段代码。 try: __import__('imp').find_module('openpyx') print('this worked') except ImportError: pass print('') print('You do not have OpenpyXl installed - it will now install') print('') 我知道我应该使用 PIP 吗? 因此,如果我将 Openpyxl 文件夹与脚本放在同一目录中,我怎么能指向它呢? 我需要更改系统路径吗? 这就是我的代码基本上开始的方式 - #!/usr/bin/env python3 import os import sys import openpyxl import time from datetime import datetime from datetime import timedelta FMT = '%H:%M'

2022-01-15 06:18:20    分类:技术分享    python   python-3.x   pip   openpyxl   python-module

Using PIP to install openpyxl for a user

I've written a script that will enable a user to have their weekly timesheet's filled out automatically and save it as a new excel spreadsheet. I thought I would be able to just have the Openpyxl folder in the same directory as the script for it to import but it does not seem to work. I have put together a bit of code based off a few other threads below to check for openpyxl before it imports. So I can hopefully have the ability to setup openpyxl. I intend to have this bit of code run during the import of the os, sys, time, datetime etc. try: __import__('imp').find_module('openpyx') print(

2022-01-13 22:45:09    分类:问答    python   python-3.x   pip   openpyxl   python-module

Django没有名为utils的模块(Django no module named utils)

问题 我知道以前有人问过这个问题,但在调查之后,我不禁觉得我错过了一些东西。 所以我之前在安装 django-compressor 时遇到了问题,但经过一番挣扎后,我设法安装了它。 当我运行我的 django 应用程序时,它在我的 manage.py 中的execute_from_command_line(sys.argv)上停止并抛出此错误: Traceback (most recent call last): File "C:\Users\PCDOM\Desktop\Power\pm_app\manage.py", line 17, in <module> execute_from_command_line(sys.argv) File "C:\Users\PCDOM\Desktop\Power\pm_app\env\lib\site-pac kages\django\core\management\__init__.py", line 385, in execute_from_command_lin e utility.execute() File "C:\Users\PCDOM\Desktop\Power\pm_app\env\lib\site-pac kages\django\core\management\__init__.py", line 354, in

2022-01-13 17:50:18    分类:技术分享    python   django   django-templates   python-module

python包使用pip安装报错(Installation error of python package using pip)

问题 我尝试安装一个名为 python-phonenumbers 的 python 模块,但出现此错误 sudo pip install git+git://github.com/daviddrysdale/python-phonenumbers.git 清理... 命令 /usr/bin/python -c "import setuptools; file ='/tmp/pip-YQ6XJC-build/setup.py';exec(compile(open( file ).read().replace( '\r\n', '\n'), file , 'exec'))" install --record /tmp/pip-s3GdMz-record/install-record.txt --single-version-externally-managed failed with /tmp/pip-YQ6XJC-build 中的错误代码 -9 在 /home/ubuntu/.pip/pip.log 中存储完整的日志 我在这里附上了完整的日志 http://paste2.org/WZzCdz7Y 更新 我错误地输入了以下行 sudo pip install git://github.com/daviddrysdale/python-phonenumbers.git 代替 sudo

2022-01-11 23:04:01    分类:技术分享    python   django   python-2.7   pip   python-module

Django no module named utils

I know this question has been asked before but after looking into it I can't help but feel I missed something. So I previously had a problem getting django-compressor installed but after a bit of struggling i managed to get it installed. When I run my django application though it stops on execute_from_command_line(sys.argv) in my manage.py and throws this error: Traceback (most recent call last): File "C:\Users\PCDOM\Desktop\Power\pm_app\manage.py", line 17, in <module> execute_from_command_line(sys.argv) File "C:\Users\PCDOM\Desktop\Power\pm_app\env\lib\site-pac kages\django\core\management\_

2022-01-11 00:40:07    分类:问答    python   django   django-templates   python-module

Installation error of python package using pip

I tried to install a python module called python-phonenumbers I got this error sudo pip install git+git://github.com/daviddrysdale/python-phonenumbers.git Cleaning up... Command /usr/bin/python -c "import setuptools;file='/tmp/pip-YQ6XJC-build/setup.py';exec(compile(open(file).read().replace('\r\n', '\n'), file, 'exec'))" install --record /tmp/pip-s3GdMz-record/install-record.txt --single-version-externally-managed failed with error code -9 in /tmp/pip-YQ6XJC-build Storing complete log in /home/ubuntu/.pip/pip.log I attached the complete log here http://paste2.org/WZzCdz7Y update I mistakenly

2022-01-09 07:50:51    分类:问答    python   django   python-2.7   pip   python-module

如何将 Python 模块拆分为多个文件?(How to split a Python module into multiple files?)

问题 我有一个包含 3 个类的 Python 模块:A、A1 和 A2。 A1 和 A2 派生自 A。A 包含对 A1 和 A2 进行操作的函数。 当它在一个 .py 文件中时,这一切都很好。 但是那个文件已经变长了,我想将 A1 和 A2 拆分成它们自己的文件。 尽管存在循环依赖,如何拆分此文件? 回答1 modA.py: class A(...): ... modA1.py: import modA class A1(modA.A): ... modA2.py: import modA class A2(modA.A): ... 模组: from modA import A from modA1 import A1 from modA2 import A2 即使 A “处理” A1s 和 A2s 你也应该没问题,因为多亏了鸭子打字,你不需要导入实际名称。 回答2 尽管存在循环依赖,但如何拆分此文件? 选项 1:打破循环:将基类放在它自己的模块中,将派生类放在其他模块中,并将对这些派生类进行操作的函数放在另一个模块中。 选项 2:忽略循环,仅将模块/包导入全局命名空间,IE: 文件 class Bar: "Frobs Quuxen" 永远不应该导入为from foo import Bar ,只需使用import foo并根据需要在函数中引用foo.Bar 。 回答3

2022-01-08 01:22:58    分类:技术分享    python   python-module