Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用请求模块时出现全局名称错误_Python_Python Requests - Fatal编程技术网

Python 使用请求模块时出现全局名称错误

Python 使用请求模块时出现全局名称错误,python,python-requests,Python,Python Requests,我有一个Python包“testPackage”,它包含两个文件functions.py和mainFunction.py。(我正在Anaconda发行版上使用Python 2.7) functions.py包含以下psuedo代码: import requests def myfunction(): req = requests.get(....) mainFunction.py调用此函数如下: import os os.chdir('path/to/the/package/') fr

我有一个Python包“testPackage”,它包含两个文件functions.py和mainFunction.py。(我正在Anaconda发行版上使用Python 2.7)

functions.py包含以下psuedo代码:

import requests

def myfunction():
  req = requests.get(....)
mainFunction.py调用此函数如下:

import os
os.chdir('path/to/the/package/')

from testPackage import *

def main():
  result = myfunction(...)
但是,我得到以下错误:

NameError: global name 'requests' is not defined

既然我已经在相应的模块中导入了requests模块,为什么会出现此错误

你能提供更多的回溯和实际代码吗?这里没有足够的帮助。您是否已确保安装了
请求
程序包?(
pip安装请求
)?@BorrajaX,这将导致导入错误,而不是名称错误。OP似乎更可能没有实际导入请求,但如果没有更多信息,除了感谢您的帮助之外,别无选择……看起来我的IPython笔记本行为怪异……在关闭/重新打开IPython后,运行相同的代码仍然有效fine@sigmavirus24,你完全正确。。。当我学会阅读的那一天,我将征服世界