【问题标题】:Importing parallel python module. Module not recognized导入并行 python 模块。模块无法识别
【发布时间】:2020-11-20 19:02:38
【问题描述】:

我有一个项目目录,用于提取和处理 twitter 数据,其中包含用于我所有配置的配置模块

twitter_data
|
|--config
|   |--configAuth.py -> a class file for configuring an api object
|   |--accessKeys.py -> a file for processing access keys for configuration
|   |--__init__.py -> used for global API
|   |--access_keys.txt
|
|--dataScraping
    |--searchUsers.py -> test file to see if twitter API works
    |--__init__.py

这是 searchUsers.py 的内容

import tweepy
from config import api
from config.configAuth import configAuth


def configTweepy(keys):
    return configAuth(keys).getApi()


def getUserList(keyWord):
    return api.search_users(keyWord)


users = getUserList('rock music')
for user in users: print(user.screen_name)

当我运行它时,我遇到了这个错误

Traceback (most recent call last):
  File "searchUsers.py", line 7, in <module>
    from config import api
ModuleNotFoundError: No module named 'config'

我尝试使用 sys.append 路径方法,但我需要它只处理 twitter_data 目录中的文件,而不必指定完整路径,因为 accessKeys.py 依赖于 access_keys.txt 文件。 有修复吗?

【问题讨论】:

    标签: python tweepy python-module


    【解决方案1】:

    我猜你正在运行 searchUsers.py 并使用 dataScraping 作为你的工作目录。

    确保您从 twitter_data 文件夹作为您的工作目录运行。

    你应该通过python -m dataScraping.searchUsers来做

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-14
      • 2017-02-03
      • 2014-02-08
      • 2021-02-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多