简体   繁体   English

ModuleNotFoundError: 没有名为“_beatbox”的模块

[英]ModuleNotFoundError: No module named '_beatbox'

I am trying to use python to connect with SF.我正在尝试使用 python 与 SF 连接。 Saw some articles that show how to use it with beatbox library and I did install it.看到一些文章展示了如何将它与 beatbox 库一起使用,我确实安装了它。 However when trying to run simple code I'm getting error below.但是,当尝试运行简单的代码时,我在下面收到错误。

Traceback (most recent call last):
  File "c:/Users/user/hello/.vscode/hello.py", line 16, in <module>
    import beatbox
  File "C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\beatbox\__init__.py", line 1, in <module>
    from _beatbox import _tPartnerNS, _tSObjectNS, _tSoapNS, SoapFaultError, SessionTimeoutError
ModuleNotFoundError: No module named '_beatbox'

I navigate to the folder where the beatbox is installed and I see there the file _beatbox.py .我导航到安装了 beatbox 的文件夹,我在那里看到了文件_beatbox.py I think the file __init__.py try to import _beatbox but cannot find it for some reason.我认为文件__init__.py尝试导入_beatbox但由于某种原因找不到它。 Any idea how to solve it?知道如何解决吗? What I'm missing?我缺少什么?

Code:代码:

import beatbox

sf_username = "xxxxxx"
sf_password = "xxxxxx"
sf_token = "xxxxxx"

def getAccount():
  sf = beatbox._tPartnerNS
  sf_client = beatbox.PythonClient()
  password = str("%s%s" % (sf_password, sf_token))
  sf_client.login(sf_username, sf_password)
  accQuery = "Select Id,Name From Account limit 5"
  queryResult = sf_client.query(accQuery)
  print ("query result: " + str(queryResult[sf.size]))
  for rec in queryResult[sf.records:]:
    print str(rec[2]) + " : " + str(rec[3])

  return

Can close the case.可以关闭案例。 I first found that in python 3+ should use beatbox3.我首先发现在python 3+中应该使用beatbox3。 But then found additional errors (possible compatibility issues).但是后来发现了额外的错误(可能是兼容性问题)。

Since I notice it taking me too long, instead I tried using library simple-salesforce 0.74.2 to connect, and it worked perfect.由于我注意到它花费了我太长时间,因此我尝试使用库 simple-salesforce 0.74.2 进行连接,并且效果很好。

Probably, Python does not know where to search for the module.也许,Python 不知道在哪里搜索模块。 By default, only the sitepackages directory and your working directory is searched.默认情况下,仅搜索 sitepackages 目录和您的工作目录。 You can resove this by placing a symbolic link to the beatbox package or moving it to the sitepackages directory您可以通过放置指向 beatbox 包的符号链接或将其移动到 sitepackages 目录来解决此问题

If you change the sitepackage folder name from "beatbox" to "_beatbox" this will solve your problem.如果您将站点包文件夹名称从“beatbox”更改为“_beatbox”,这将解决您的问题。 You can then import it as: "import beatbox" and it will load in Python.然后您可以将其导入为:“import beatbox”,它将在 Python 中加载。

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

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