ModuleNotFoundError: No module named '_beatbox' - python

I am trying to use python to connect with SF.
Saw some articles that show how to use it with beatbox library and I did install it.
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.
I think the file __init__.py try to import _beatbox but cannot find it for some reason.
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. 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.

Probably, Python does not know where to search for the module. By default, only the sitepackages directory and your working directory is searched. You can resove this by placing a symbolic link to the beatbox package or moving it to the sitepackages directory

If you change the sitepackage folder name from "beatbox" to "_beatbox" this will solve your problem. You can then import it as: "import beatbox" and it will load in Python.

Related

ModuleNotFoundError: No module named 'createCredentialsXML'

I have a question about my new python project. It is the first time that I use different folders for my project.
I have the following structure:
project
src
securityFunc
__init__.py
createCredentialsXML.py
main.py
I work in PyCharm environment.
After pressing Play i get the error message:
Traceback (most recent call last):
File "C:\project\src\main.py", line 1, in <module>
from securityFunc import *
File "C:\project\src\securityFunc\__init__.py", line 1, in <module>
from createCredentialsXML import *
ModuleNotFoundError: No module named 'createCredentialsXML'
My main function looks like this:
from securityFunc import *
if __name__ == '__main__':
generate_key()
__init__.py:
from createCredentialsXML import *
createCredentialsXML.py:
def generate_key():
key = base64.urlsafe_b64encode(os.urandom(2048))
with open("../key/secret.key", "wb") as key_file:
key_file.write(key)
I tried using Path or sys.path to fix the problem. But it does not work.
Can you please tell me how to fix the problem?
Since you're doing a relative import, you need to add a . before your module name:
from .createCredentialsXML import *
The dot means the module is found in the same directory as the code importing the code.
You can read more about it here
createCredentialsXML.py works in the module securityFunc; you must specify the scope of the import. Using
from securityFunc.createCredentialsXML import *
in securityFunc.__init__.py should work.

Module has no attribute error in python3

contents of io.py
class IO:
def __init__(self):
self.ParsingFile = '../list'
def Parser(self):
f = open(ParsingFile, 'r')
print(f.read())
contents of main.py
import sys
sys.path.insert(0, "lib/")
try:
import io
except Exception:
print("Could not import one or more libraries.")
exit(1)
print("Libraries imported")
_io_ = io.IO()
When I run python3 main.py I get the following error:
Libraries imported
Traceback (most recent call last):
File "main.py", line 11, in <module>
_io_ = io.IO()
AttributeError: module 'io' has no attribute 'IO'
Any idea what's going wrong?
My file was called io. It seems that there already exists a package called io which caused the confusion.
Your package name (io) conflicts with the Python library's package with the same name, so you actually import a system package.
You can check this by printing io.__all__.
Changing io.py to something else is probably the best way to go to avoid similar problems. Otherwise, you can use an absolute path.
try
from io import IO
That worked for me when trying to import classes from another file
this has more information:
Python module import - why are components only available when explicitly imported?

Any way to see where python is importing a module from?

So I installed the facebook module, realized it was the wrong one, used pip to uninstall and then installed facebook-sdk. Here is my code:
import facebook
token = '[token]'
graph = facebook.GraphAPI(token)
profile = graph.get_object("me")
friends = graph.get_connections("me", "friends")
friend_list = [friend['name'] for friend in friends['data']]
print friend_list
and get
Traceback (most recent call last):
File "C:\Users\mgraves\Desktop\facebook.py", line 1, in <module>
import facebook
File "C:\Users\mgraves\Desktop\facebook.py", line 5, in <module>
graph = facebook.GraphAPI(token)
AttributeError: 'module' object has no attribute 'GraphAPI'
When looking this up, EVERY result says to uninstall facebook and facebook-sdk and reinstall facebook-sdk. And I have, many many times. I searched /python27/ for facebook afterwards to make sure the files were gone.
Is there any way on a windows machine to trace back where I am importing "facebook" from?
Module objects have a __file__ attribute, and the object representation also includes the file:
print facebook
print facebook.__file__
In your case, you are importing your own script; you named it facebook as well and are masking the installed module:
File "C:\Users\mgraves\Desktop\facebook.py", line 1, in <module>
import facebook
File "C:\Users\mgraves\Desktop\facebook.py", line 5, in <module>
graph = facebook.GraphAPI(token)
Note the filename in the first line, then the fact that the same file is used for that import. Python stores the main script as __main__, so importing the script itself results in another module being created for the actual filename.

Sending E-mail Hotmail Account via Raspberry Pi

I just write this code in Python under Raspbian OS:
import smtplib
from = '****#hotmail.de'
to = '****#hotmail.de'
msg = 'Testmail'
usr = '****#hotmail.de'
psw = '****'
server = smtplib.SMTP('smtp.live.de',25)
server.login (usr,psw)
server.sendmail (from, to, msg)
server.quit()
And get following Error-Message:
Traceback (most recent call last):
File "ail.py", line 1, in <module>
import smtplib
File "/usr/lib/python2.7/smtplib.py", line 46, in <module>
import email.utils
File "/home/pi/email.py", line 6, in <module>
smtp =smtplib.SMTP('smtp.live.com',25)
AttributeError: 'module' object has no attribute 'SMTP'
What is my fault? Could somebody help me - please?
Regards
Your problem is that you named your script email.py, or maybe an earlier version of it. That means that it shadows the standard-library email module/package. So, when smtplib tries to import email or import email.utils, it gets your code instead of the stdlib code it wants.
The solution is to rename your script to not match any of the stdlib modules and packages (or at least not any of the ones you're directly or indirectly using).
If you've already renamed it to ail.py (as the traceback seems to suggest) and it's still causing problems, make sure to delete your original email.py, and any .pyc/.pyo files of the same name. As long as they're in the current working directory (or elsewhere on sys.path), they can still interfere with the stdlib.

Import Error using cPickle in Python

I am using Pickle in Python2.7. I am getting error while using cPickle.load() method. The code and error is shown below. Can someone guide me through this?
Code:
#! usr/bin/python
import cPickle
fo = open('result','rb')
dict1 = cPickle.load(fo)
Error:
Traceback (most recent call last):
File "C:\Python27\test.py", line 7, in <module>
dicts = cPickle.load(fo)
ImportError: No module named options
It seems like you can not do
import options
but when you or someone else did
cpickle.dump(xxx, open('result', 'rb'))
there was an object with a class or function of a module options that existed at this point in time, in xxx.
Solution
You can open the file binarily and replace options with the module you replaced the old module options with.
You probably created the file in your package like in module package.main by executing the file main.py or something like it, having a module options in the same directory.
Now you do import package.main, try to read the file and options is now called package.options and the module options can not be found.
How did you create this file? How do you load it now? cPickle/pickle does not transfer source code - so if you use a function you need the module when you load it.

Categories

Resources