简体   繁体   English

Python - 没有名为foo的模块

[英]Python - No module named foo

I'm new to python and I am trying to write a simple program for an led cube. 我是python的新手,我正在尝试为led立方体编写一个简单的程序。 First I need to execute one of the other sample programs provided, but I'm getting the error "No module named cube_interface" when I try and run a python program. 首先,我需要执行其中一个提供的示例程序,但是当我尝试运行python程序时,我收到错误“No module named cube_interface”。

Now before you mark this question as duplicate, and refer me to the 7,776 similar questions stack overflow, let me tell disclose that I've already tried implementing the solutions provided on 14 other SO questions, and followed 3 blogs covering how to fix this error, with no luck. 现在在你将这个问题标记为重复之前,并向我推荐7,776个类似问题的堆栈溢出,让我告诉我已经尝试实现其他14个SO问题提供的解决方案,并关注3个博客,介绍如何修复此错误,没有运气。

OS: Mac OsX 10.8.1 操作系统:Mac OsX 10.8.1
Python: 2.7.5 Python:2.7.5
Repo: https://github.com/chadharrington/all_spark_cube 回复: https//github.com/chadharrington/all_spark_cube

The example program is src/tetris.py 示例程序是src / tetris.py

The module is src/all_spark_cube_client 该模块是src / all_spark_cube_client

   ├── Makefile
    └── src
        ├── LICENSE.txt
        ├── all_spark_cube_client
        │   ├── __init__.py
        │   └── __init__.pyc
        ├── all_spark_cube_client.egg-info
        │   ├── PKG-INFO
        │   ├── SOURCES.txt
        │   ├── dependency_links.txt
        │   ├── not-zip-safe
        │   ├── requires.txt
        │   └── top_level.txt
        ├── build
        │   ├── bdist.macosx-10.9-intel
        │   └── lib
        │       └── all_spark_cube_client
        │           └── __init__.py
        ├── client_demo.py
        ├── colors.py
        ├── dist
        │   └── all_spark_cube_client-0.1-py2.7.egg
        ├── load_test.py
        ├── setup.py
        ├── supervisord.conf
        ├── supervisord_init_script.debian
        ├── supervisord_init_script.redhat
        └── tetris.py

When I try and run the tetris.py program, I get an error "No module named.." 当我尝试运行tetris.py程序时,出现错误“没有模块命名..”

python tetris.py 
Traceback (most recent call last):
  File "tetris.py", line 5, in <module>
    from all_spark_cube_client import CubeClient
  File "/Users/sowen/Code/all_spark_cube/software/clients/python_client/src/all_spark_cube_client/__init__.py", line 8, in <module>
    from cube_interface import CubeInterface
ImportError: No module named cube_interface

Many of the answers suggest adding pwd . 许多答案建议添加pwd。 /Library/Python ect.. to the PYTHONPATH. / Library / Python等...到PYTHONPATH。 I've tried implementing all of them independently, and even combined all suggestions into one frakenstein path as shown, with no luck. 我已经尝试独立实现所有这些,甚至将所有建议合并到一个frakenstein路径中,如图所示,没有运气。

cd ~/Code/all_spark_cube/software/clients/python_client
export PYTHONPATH=$PATH:$PYTHONPATH:`pwd`:`pwd`/src:.:/Library/Python/2.7/site-packages/

I've tried building the python module 我试过构建python模块

$sudo python setup.py build
 running build
 running build_py
 file all_spark_cube_client.py (for module all_spark_cube_client) not found
 file all_spark_cube_client.py (for module all_spark_cube_client) not found

I've tried installing the python module (It doesn't give any errors, but I still am unable to run tetris.py) 我已经尝试安装python模块(它没有给出任何错误,但我仍然无法运行tetris.py)

 cd ~/Code/all_spark_cube/software/clients/python_client/src/
 sudo python setup.py install

How can I execute the tetris.py program? 我该如何执行tetris.py程序?

Additional Resources 其他资源

http://docs.python.org/2/using/mac.html http://docs.python.org/2/using/mac.html
http://www.confusedcoders.com/random/python-module-importerror-no-module-named-pocketsphinx http://www.confusedcoders.com/random/python-module-importerror-no-module-named-pocketsphinx

You forgot to build cube_interface : 你忘了构建cube_interface

See: https://github.com/chadharrington/all_spark_cube/tree/master/software/thrift 请参阅: https//github.com/chadharrington/all_spark_cube/tree/master/software/thrift

You need to build this with the gen_py tool. 您需要使用gen_py工具构建它。

ie: ( I assume :): 即:( 我假设 :):

cd /path/to/all_spark_cube/software/thrift/
make
cp cube_interface.py /path/to/python/site-packages

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

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