问题描述
我正在尝试将 Google Cloud Storage 功能添加到已运行具有重要功能的 Python GAE 应用程序中.我在我的开发计算机上完全在 PyCharm 中工作,这是一台运行 OS X 10.9.5 的 Mac.
I am trying to add Google Cloud Storage functionality to a Python GAE app that is already running with significant functionality. I work entirely within PyCharm on my development computer, which is a Mac running OS X 10.9.5.
我创建了一个包含以下语句的新 Python 模块:
I have created a new Python module that contains this statement:
import cloudstorage as gcs
如 https://cloud.google 上的示例代码所示.com/appengine/docs/python/googlecloudstorageclient/getstarted
当我第一次添加该行时,PyCharm 在编辑器中显示没有名为 cloudstorage 的模块".
When I first added that line, PyCharm said "No module named cloudstorage" in the editor.
然后我按照 上的pip"和svn"说明进行操作https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/download下载 GCS 客户端库.
I then followed both the "pip" and the "svn" instructions at https://cloud.google.com/appengine/docs/python/googlecloudstorageclient/downloadto download the GCS Client Library.
在尝试遵循这些说明时,考虑到我之前使用此编程环境的经验,我实际上尝试使用pip"三遍:
In trying to follow those instructions, taking into account my prior experience with this programming environment, I actually tried using "pip" three times:
- 曾经没有-t"选项,因为我以前从未需要带有pip"的选项
- 曾经使用-t"选项指定我的应用程序目录的lib"子目录
- 使用一次:
pip install GoogleAppEngineCloudStorageClient -t/Applications/GoogleAppEngineLauncher.app//Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib
,因为我不确定说明"是什么意思<your_app_directory/lib>"
- Once without the "-t" option, since I've never needed that option with "pip" before
- Once using the "-t" option to specify my application directory's "lib" subdirectory
- Once using:
pip install GoogleAppEngineCloudStorageClient -t /Applications/GoogleAppEngineLauncher.app//Contents/Resources/GoogleAppEngine-default.bundle/Contents/Resources/google_appengine/lib
, since I wasn't sure what the instructions meant by "<your_app_directory/lib>"
如前所述,我还执行了svn"命令.然后,如 安装 python google 云存储客户端中所述Ubuntu 14.04,我运行了cd gcs-client/src"和sudo python setup.py install".我在我的用户根目录中运行了这些命令.
As mentioned, I also executed the "svn" command. Then, as mentioned in install python google cloud storage client on Ubuntu 14.04, I ran "cd gcs-client/src" and "sudo python setup.py install". I ran these commands in my user root directory.
每次成功但不同地安装 GCS 客户端库后,我查看了我的模块的 PyCharm 编辑器窗口,它总是出现相同的没有名为 cloudstorage 的模块"错误.但作为一个实验,我也会尝试重新启动 PyCharm,并尝试运行我的应用程序.
After each of those successful but different installations of the GCS Client Library, I looked at the PyCharm editor window for my module, and it always had the same "No module named cloudstorage" error. But as an experiment, I would also try restarting PyCharm, and also try running my app.
在某些时候,编辑器窗口停止显示错误.不是在上述步骤之一之后,而是在我离开阅读各种网页然后再回来查看错误之后.我不知道是哪个安装消除了 PyCharm 编辑器中的错误消息.
At some point, the editor window stopped showing the error. It was not immediately after one of those steps above, but after I would go away to read various webpages and then come back to look at the error again. I don't know which of the installations was the one that got rid of the error message in the PyCharm editor.
在任何情况下,每当我尝试运行应用程序(同样,在 PyCharm 中)时,我总是在同一个导入语句中收到运行时错误ImportError: No module named cloudstorage".
In any case, whenever I try to run the app (again, inside PyCharm), I always get the runtime error "ImportError: No module named cloudstorage" on the same import statement.
此应用的运行/调试配置页面同时选中了将内容根添加到 PYTHONPATH"和将源根添加到 PYTHONPATH".
The Run/Debug Configuration page for this app has both "Add content roots to PYTHONPATH" and "Add source roots to PYTHONPATH" checked.
当然,我想要的主要帮助是如何克服No module named cloudstorage"运行时错误,即使 import 语句不再显示错误.
Of course the main help I want is how to get past the "No module named cloudstorage" runtime error, even though the import statement no longer shows an error.
我想我还有多达三个 GCS 客户端库的虚假版本.我更关心通过未找到模块",因为它是一个阻碍,但如果你知道我如何删除虚假版本,以便它们不只是躺在那里,我会是最也感谢您的帮助.
I think I also have as many as three spurious versions of the GCS Client Library. I'm much more concerned with getting past "Module not found", since it's a show-stopper, but if you have any idea how I can delete the spurious versions so that they're not just lying around, I'd be most grateful for that help as well.
推荐答案
如果cloudstorage"目录在/lib/cloudstorage
,那么import语句必须指定lib":
If the "cloudstorage" directory is at <app>/lib/cloudstorage
, then the import statement has to specify "lib":
import lib.cloudstorage
就我而言,它是:
import lib.cloudstorage as gcs
对了,<app>/lib/GoogleAppEngineCloudStorageClient-1.9.5.0-py2.7.egg-info
目录好像不需要,可以删除.
By the way, the <app>/lib/GoogleAppEngineCloudStorageClient-1.9.5.0-py2.7.egg-info
directory does not seem to be needed and can be deleted.
这篇关于在 OS X 下的 PyCharm 上运行 GAE GCS,运行时错误“No module named cloudstorage";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!