上下文:
我正在尝试构建一个Django应用程序,它使用这个包:django-minio-存储。我试图用以下类扩展包中的某个类:
@deconstructible
class MinioStoreStorage(MinioStorage):
def __init__(self, bucket_name):
client = create_minio_client_from_settings()
base_url = bucket_name
# base_url = get_setting("MINIO_STORAGE_STATIC_URL", None)
bucket_name = bucket_name
auto_create_bucket = True
presign_urls = True
super(MinioStoreStorage, self).__init__(
client,
bucket_name,
auto_create_bucket=auto_create_bucket,
base_url=base_url,
presign_urls=presign_urls
)问题:
我不能导入函数create_minio_client_from_settings。此函数驻留在包的文件storage.py中。驻留在类MinioStorage中的同一个文件。我还可以成功地导入另一个函数(get_setting),它位于同一个文件中,没有问题地使用它,但是尝试为create_minio_client_from_settings做同样的操作会引发一个ImportError。以下是我使用的导入:
from minio_storage.storage import get_setting
# Succeeds
from minio_storage.storage import create_minio_client_from_settings
Traceback (most recent call last):
File "<console>", line 1, in <module>
ImportError: cannot import name 'create_minio_client_from_settings'storage.py
下面是包的代码片段:
@deconstructible
class MinioStorage(Storage):
"""An implementation of Django's file storage using the minio client.
The implementation should comply with
https://docs.djangoproject.com/en/dev/ref/files/storage/.
"""
...
...
...
def get_setting(name, default=_NoValue, ):
result = getattr(settings, name, default)
if result is _NoValue:
print("Attr {} : {}".format(name, getattr(settings, name, default)))
raise ImproperlyConfigured
else:
return result
def create_minio_client_from_settings():
endpoint = get_setting("MINIO_STORAGE_ENDPOINT")
access_key = get_setting("MINIO_STORAGE_ACCESS_KEY")
secret_key = get_setting("MINIO_STORAGE_SECRET_KEY")
secure = get_setting("MINIO_STORAGE_USE_HTTPS", True)
client = minio.Minio(endpoint,
access_key=access_key,
secret_key=secret_key,
secure=secure)
return client问题:
进一步调查:
我一直在更多地研究这个问题,这里有一些评论和一种观察异常现象的更可重复的方法。在创建了Django项目并安装了有问题的包之后,我使用:python manage.py shell启动了shell,并使用了以下命令:
>>> import minio_storage
>>> dir(minio_storage)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__', '__version__', 'storage']
>>> help(minio_storage.storage)help(minio_storage.storage)将显示一个描述包提供的类和函数的手册页面。在函数类别下,只有一个函数可用,它就是get_setting()函数。
create_minio_client_from_settings()不像get_setting()那样出现呢?版本和依赖项
下面是命令的结果:pipenv graph
django-minio-storage==0.1.0
- django [required: >=1.9, installed: 1.11.6]
- pytz [required: Any, installed: 2017.2]
- minio [required: >=1.0.2, installed: 2.2.5]
- certifi [required: Any, installed: 2017.7.27.1]
- pytz [required: Any, installed: 2017.2]
- urllib3 [required: Any, installed: 1.22]
djangorestframework==3.7.1
flake8==3.5.0
- mccabe [required: >=0.6.0,<0.7.0, installed: 0.6.1]
- pycodestyle [required: >=2.0.0,<2.4.0, installed: 2.3.1]
- pyflakes [required: >=1.5.0,<1.7.0, installed: 1.6.0]
Pillow==4.3.0
- olefile [required: Any, installed: 0.44]发布于 2017-10-31 13:38:28
您的django-minio-storage包已经过时,但这并不是您的错--在撰写本文时,PyPi包本身已经过时了。
您正在运行的版本不包含您要寻找的函数。从GitHub下载包的源代码,并在那里运行-您将得到您想要的行为:https://github.com/py-pa/django-minio-storage
发布于 2017-10-31 18:04:24
解决了
正如用户souldeux所指出的,我的包裹过时了。我使用pipenv安装它,它不是一个与最新版本匹配的版本。我在一边做着我过时的包,另一边写着来自github的新代码。
他提供的链接很有用,但我结束了使用另一个所以回答直接从github安装软件包。更具体地说,就我而言:
pipenv install git+https://github.com/py-pa/django-minio-storage.git#egg=django-minio-storagehttps://stackoverflow.com/questions/47018200
复制相似问题