ModuleNotFoundError: No module named 'binance.client'; 'binance' is not a package - python

Hey i am new to both Stack Over Flow and Python, but wanting to learn and hoping someone can assist me here.. I am trying to develop a binance trading bot within python. Please see my script below:
from binance.client import Client
class Trader:
def __init__(self, file):
self.connect(file)
""" Creates Binance client """
def connect(self,file):
lines = [line.rstrip('\n') for line in open(file)]
key = lines[0]
secret = lines[1]
self.client = Client(key, secret)
""" Gets all account balances """
def getBalances(self):
prices = self.client.get_withdraw_history()
return prices
filename = 'API credentials.txt'
trader = Trader(filename)
balances = trader.getBalances()
print(balances)
This script is giving me a module not found error please see full details below:
PyDev console: starting.
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32
runfile('C:/Users/ryanf/PycharmProjects/trading bot/trader.py', wdir='C:/Users/ryanf/PycharmProjects/trading bot')
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Program Files\JetBrains\PyCharm Edu 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "C:\Program Files\JetBrains\PyCharm Edu 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "C:/Users/ryanf/PycharmProjects/trading bot/trader.py", line 1, in <module>
from binance.client import Client
File "C:\Program Files\JetBrains\PyCharm Edu 2020.1.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'binance.client'; 'binance' is not a package
Hoping some one can offer some advice here, it would be very much appreciated.

Make sure you don't have any files named "binance" in the same folder - that's what happened to me.

Would recommend the docs: https://docs.python.org/3/reference/import.html These are very long docs, but here are the "highlights":
See docs on path entry finders. You can import sys; print(sys.path) before any import statement, and also check PYTHONPATH environment variable where you're running the script. If you know where your package or module is located, ensure that that location is listed from the statement above.
See docs on installing libraries/modules -- Assuming you have installed pip, did you run pip install python-binance at any point, and if you run pip list from the command line, is "binance" listed?
If binance is a subdirectory in current directory, you may be missing an __init__.py file -- See docs on packages.
When you change the PYTHONPATH or make other changes, beware of ambiguity; avoid creating multiple sources where a module might be coming from, and name your modules/packages in a way as to avoid shadowing an existing module. See documentation on precedence of search paths

I tried a lot of things already here on google but nothing was useful, then I tired pip install python-binance==0.7.5 instead of pip install python-binance==0.7.9, and I was successful to import " from binance.client import Client.
Beside this, I also renamed my two binance.py files as binance.client.py, and it worked for me.
You can find your binance.py files in your python3 site packages folder. Just go there and search binance.py, you will find it.

In my case the problem was resolved by using:
pip install python-binance
instead of:
pip install binance
Hope it helps someone.

by calling your file binance.py, and then trying to import from binance.client python is looking in your binance.py file.
If you rename your local file then you won't have an issue.

I encountered the same problem and found that it was because I have installed python twice from two different sources (python.org and Microsoft store). By changing the python source in the VS Code, the issue was solved.

I know this is an old question, but i have just encountered it, and here are all possible ways of solving the problem
Look up, if have name any file binance.py - rename it.
you might have installed it from 2 different sources (python2, python3)
You might need to update pip.
In case if you are using conda env, even if u have set your virtual env in that folder - you have to switch python version in conda itself.
Here is where it can be done is VScode

Related

Import errors between some python moduls/functions/variables

This code worked on Friday without problems and still running on a colleagues laptop, but I cannot run it anymore.
As you can see in the screenshot, my editor doesnt find some moduls anymore and the pylint Error "E0401: Unable to import" occurs.
The missing file exists in the folder Settings, as you can see in the Explorer on the left side.
Today I deactivated/activated pylint, reinstalled vs code and python, added the init.py to Settings folder, tried the same code in eclipse, modified the Path enviroment variable and created the PYTHONPATH enviroment variable. All this with no success:/
I am greatful for each hint, which provide me to solve this problem.
The error output as text:
Windows PowerShell
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.
PS C:\Users\Evgenij\Desktop\Desktop\Eth_Test_Dev> & C:/Python27/python.exe c:\Users\Evgenij\Desktop\Desktop\Eth_Test_Dev\Code\__TC__Template.py
Traceback (most recent call last):
File "c:\Users\Evgenij\Desktop\Desktop\Eth_Test_Dev\Code\__TC__Template.py", line 36, in <module>
from Lib.IHR_EthApi import EthApi as ETH
File "c:\Users\Evgenij\Desktop\Desktop\Eth_Test_Dev\Code\Lib\IHR_EthApi.py", line 6, in <module>
from IHR_GeneralApi import GeneralApi as SYS
File "c:\Users\Evgenij\Desktop\Desktop\Eth_Test_Dev\Code\Lib\IHR_GeneralApi.py", line 4, in <module>
import IHR_TestSuiteConfig.py
ImportError: No module named IHR_TestSuiteConfig.py
PS C:\Users\Evgenij\Desktop\Desktop\Eth_Test_Dev>
In your code you have the line:
import IHR_TestSuiteConfig.py
That won't work because you don't specify modules to import by file name but by module name, e.g.:
import IHR_TestSuiteConfig
But looking at your screenshot you have a bigger issue of the code being kept in a Settings directory at the same level as your Lib directory containing the code you are importing into.
You need to either anchor all of your code up a level so you can do:
from ..Settings import IHR_TestSuiteConfig
Or you need to manipulate your PYTHONPATH environment variable to put Settings directly on to sys.path (in VS Code you can create a .env file to do this, but it won't' affect running Python from the terminal, only when VS Code runs e.g. Pylint).

OpenLabs connector Magento OpenERP 7.0

I'm trying to connect my OpenERP 7.0 to my Magento webSite 1.9.
I'm using the connector developed by openLabs https://github.com/openlabs/magento_integration
I follow the instructions of https://openerp-magento-connector.readthedocs.io/en/develop/introduction.html#installation
But after 3 restores of my OpenERP, I still have an error when I tried to update my modules to get my Magento module.
File "/opt/openerp/davidts/appserver-dts/parts/openerp-7.0-20140124-002431/openerp/addons/base/module/module.py", line 617, in update_list
handler.load_addons()
File "/opt/openerp/davidts/appserver-dts/parts/openerp-7.0-20140124-002431/openerp/addons/web/http.py", line 580, in load_addons
m = import('openerp.addons.' + module)
File "/opt/openerp/davidts/appserver-dts/parts/openerp-7.0-20140124-002431/openerp/modules/module.py", line 133, in load_module
mod = imp.load_module('openerp.addons.' + module_part, f, path, descr)
File "/opt/openerp/davidts/appserver-dts/parts/openerp-7.0-20140124-002431/openerp/addons/magento_integration-develop/init.py", line 9, in
import magento_
File "/opt/openerp/davidts/appserver-dts/parts/openerp-7.0-20140124-002431/openerp/addons/magento_integration-develop/magento_.py", line 17, in
import magento
ImportError: No module named magento
I'm thinking this module isn't stable but when I read on forums, I saw people saying it works.
Some of this people or someone else can explain to me how they did ? Or another solution ? I'm open to multiple ways as it works. (But I haven't the possibility to upgrade my OpenERP in 8.0 or 9.0).
Thanks
EDIT : To #CZoellner
First, thx for your helpful answers
Ok, I solve the problem, my python lib was installed but my openERP installer didn't find it. So I modify the script to add the way of my module in sys.path. This error is resolved.
But now, I have another error seems the first
File "/opt/openerp/davidts/appserver-dts/parts/openerp-7.0-20140124-002431/openerp/addons/magento_integration-develop/init.py", line 10, in
import country
File "/opt/openerp/davidts/appserver-dts/parts/openerp-7.0-20140124-002431/openerp/addons/magento_integration-develop/country.py", line 18, in
import pycountry
ImportError: No module named pycountry
and the sys.path has already the good way
[...
'/usr/local/lib/python2.7/dist-packages/pycountry-1.20-py2.7.egg',
...]
I never develop in python so I certainly missed something
Ok, So I again restoring my snapshot ...
But now, instead using the installer, I downloaded the library manually and install it one by one.
So I install, pycountry lib and magento lib. I update the file "magento_.py" and "pycountry.py" of openLab connector to add the path of my library on sys.path.
Something like that
import sys
sys.path.append("/usr/local/lib/python2.7/dist-packages/pycountry-1.20-py2.7.egg/")
I run the setup of openLabs connector and after I launch update of openERP.
And it finally works ! whew !
Anyway thx for your useful answers !

Error Importing SHTOOLS Python Package

I am trying to import the spherical harmonic toolbox (SHTOOLS) in python. I have the files downloaded and unzipped and am using RedHat.
I added the package's path to my python system path and when I go to import the package, I get this error:
>>import pyshtools
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pyshtools/__init__.py", line 49, in <module>
load_documentation()
File "pyshtools/__init__.py", line 27, in load_documentation
from . import _SHTOOLS
ImportError: cannot import name _SHTOOLS
I can not seem to figure out what the issue is. I checked that the path to this folder was actually added to the system path and it was.
Is this an issue on my end? Or is it possible that I have something downloaded incorrectly? If so, how would I go about fixing this issue?
The SHTOOLS package needs to be built with make first to compile the Fortran libraries. The wiki on Github gives directions on which libraries are required - libblas-dev, liblapack-dev, g++, gfortran, and libfftw3-dev (these are the Ubuntu packages, they may have slightly different names on Redhat). Once these are installed, you need to run make, then sudo make all to install the Fortran and Python components. The Makefile has a lot of good comments in it, I'd recommend reading through it before running make.

Dreamhost - ImportError: No module named _weakrefset

Dreamhost upgraded a number of servers this weekend, including the one I was on. It broke my configuration, so as recommended I attempted to delete the virtual environment it was running on and attempted to re-set it up. However, when I try to navigate to the site, I get this:
Traceback (most recent call last):
File "/home/thesp/mysite.com/env/lib/python2.7/site-packages/site.py", line 74, in <module>
__boot()
File "/home/thesp/mysite.com/env/lib/python2.7/site-packages/site.py", line 2, in __boot
import sys, os, os.path
File "/home/thesp/lib/python2.7/os.py", line 400, in <module>
import UserDict
File "/home/thesp/lib/python2.7/UserDict.py", line 83, in <module>
import _abcoll
File "/home/thesp/lib/python2.7/_abcoll.py", line 11, in <module>
from abc import ABCMeta, abstractmethod
File "/home/thesp/lib/python2.7/abc.py", line 8, in <module>
from _weakrefset import WeakSet
ImportError: No module named _weakrefset
I've got Python 2.7.8 installed and running, and from shell access, both in and out of my virtual environment when I run Python, I'm pulling up the correct version (which is different from the native version installed, so it's finding my setup). Other posts which reference this error message seem to think it's a problem with not having an upgraded version of virtualenv, but its version is higher than the troublesome version. (I'm running 1.11.6.)
Weirder still, I can shell into Python, type from _weakrefset import WeakSet, and I don't get import errors. I'm running Django 1.6 and I can python manage.py runserver with no errors, but the web server is throwing up before it ever sees Django.
In the traceback, the first two lines are pulling from my virtual environment, but the remaining ones don't seem to be, and I have no idea why, or even if that's relevant.
Any advice on what I should do next? I've about pulled my hair out on this one! I can post any additional information that would help troubleshoot. Thanks!
Well, I feel silly now. I went to the /home/thesp/lib/python2.7/ directory and downloaded _weakrefset.py, like so:
wget http://svn.python.org/projects/python/trunk/Lib/_weakrefset.py
...and now everything seems to be running fine. There was a _weakrefset.pyo file in the directory, so I'm not sure why _weakrefset.py never made it in, but this seems to have done the trick.
Now, that doesn't solve the mystery of why the stack trace switches directories like it does, but it's running now, so I'll take it for now!

Jython 2.5.1: "ImportError: No Module named os"

I looked through the other posts and bug reports and couldn't figure out what's causing this. I'm using Jython 2.5.1, in a Java project in Eclipse (Ubuntu 8.10). It has been added to the project as a standalone .jar file (I just replaced the old Jython 2.1 jar with this one).
I'm running a script that uses the threading.py class. At some point the statement "import os" is evaluated from linecache.py and I get this error, which I can't seem to figure out how to fix:
'Execution failed. Traceback (most recent call last):
File "<string>", line 1, in <module>
File "../lib/python/threading.py", line 6, in <module>
import traceback
File "../lib/python/traceback.py", line 3, in <module>
import linecache
File "../lib/python/linecache.py", line 9, in <module>
import os
ImportError: No module named os'
What do you mean with "the jar that comes with the 2.5 download"? Did you extract the contents and use jython.jar or did you run the installer? If you just extracted and didn't run the installer your jython.jar will miss the whole LIB folder.
Can you check if jython.jar contains a LIB folder? (e.g. open jython.jar with 7z or WinZip).
Or try copying the LIB folder in the same folder where jython.jar resides.
Did you try setting these properties. Jython Registry. e.g. via -Dpython.home in the eclipse run configuration.
python.cachedir
python.path
python.home
How is the jar named? If similar to jython-complete.jar try renaming it to jython.jar
Something is wrong at a very deep level, but it's probably easy to fix. You are seeing an error that happens while trying to report some other error.
Probably you have your PYTHONPATH misconfigured. I don't know the details of Jython or Eclipse running Jython, but it looks like you have no standard library available to you.
If you are getting maven, using the dependency jython-standalone instead of jython may help (at least it did for me in a maven project with jython-standalone-2.5.3)

Categories