模块A包括import B在其顶部.然而在试验条件下,我想嘲笑 B的A(模拟A.B)和进口完全避免B.
实际上,B并非故意安装在测试环境中.
A是被测单位.我必须导入A及其所有功能.B是我需要模拟的模块.但是我如何在A中模拟B并阻止A导入真实B,如果A做的第一件事就是导入B?
(没有安装B的原因是我使用pypy进行快速测试,不幸的是B还与pypy不兼容.)
怎么可以这样做?
我正在从 Azure 机器学习笔记本运行 pyspark。我正在尝试使用 dbutil 模块移动文件。
from pyspark.sql import SparkSession
spark = SparkSession.builder.getOrCreate()
def get_dbutils(spark):
try:
from pyspark.dbutils import DBUtils
dbutils = DBUtils(spark)
except ImportError:
import IPython
dbutils = IPython.get_ipython().user_ns["dbutils"]
return dbutils
dbutils = get_dbutils(spark)
dbutils.fs.cp("file:source", "dbfs:destination")
Run Code Online (Sandbox Code Playgroud)
我收到此错误: ModuleNotFoundError:没有名为“pyspark.dbutils”的模块 有解决方法吗?
这是另一个 Azure 机器学习笔记本中的错误:
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-183f003402ff> in get_dbutils(spark)
4 try:
----> 5 from pyspark.dbutils import DBUtils
6 dbutils = DBUtils(spark)
ModuleNotFoundError: No module named 'pyspark.dbutils'
During handling of the above exception, another exception occurred:
KeyError …Run Code Online (Sandbox Code Playgroud) pyspark databricks azure-databricks azure-machine-learning-service dbutils