Forums

Problem with binance.client

Hello! First of all, I apologize, I'm not very good with English :)) I have a problem wiht binance.client. I tried to run a program with three modules to import - asyncio, smtplib and binance.client. I wrote: "from binance.client import Client"and when run the program I receive message: "from binance.client import Client ModuleNotFoundError: No module named 'binance.client'; 'binance' is not a package". In my computer the same program is running without any problems. What can I do to solve this?

That sounds like you have something in your Python path called "binance" that is colliding with the module. Make sure that you do not have any Python files or directories that are called "binance" (or "binance.py") that are not the binance module that you want to import from.

Thank you for response, glenn. Yes, I realy had one folder with "binance" as one of the name words. I renamed the file but situation is the same - the program doesn't run. The files with "binance'' that I have are the ones in the "venv\lib\site-packages" folder. These folders are: "binance", "binance.py" and "binance-0.3.dist-info".

Are you sure that you run your code in that virtual environment?

Yes, I think so :)). What do you mean?

The path where your binance package is installed is a virtualenv. Did you activate that virtualenv before you ran your code?

I created virtualenv with bash but I cant install the needed packages for my program. How can I do this? I searched already in internet how to do this and now I am more confused.

See the first few sections here: https://help.pythonanywhere.com/pages/Virtualenvs/

Yeah, I've already seen that and follow the steps but the result is the same. Just to notice I use free account and run my program as schedule task.

What is the result?

"from binance.client import Client ModuleNotFoundError: No module named 'binance.client'; 'binance' is not a package"

Then you still have something on your Python path that is named "binance" that is not a Python module.

Maybe. When I search "binance" in my folders the only "binance" files I have are in "pycharm projects" folder in "venv". I have two projects with installed binance packages. Could the problem be there?

I think from what you're saying that you're running the commands that are generating that error in a console. Could you start a new console, then try to run the program, and then post here exactly what commands you entered, and the error messages that you got?

Here it is what I run with bash: 13:35 ~ $ ls README.txt Trading 07:47 ~ $ python --version Python 3.9.5 07:47 ~ $ python3.9
Python 3.9.5 (default, May 27 2021, 19:45:35) [GCC 9.3.0] on linux Type "help", "copyright", "credits" or "license" for more information.

quit() 07:50 ~ $ python3.9 Trading /usr/local/bin/python3.9: can't find 'main' module in '/home/Madmartigan/Trading' 07:55 ~ $ python3.9 Trading/big_crypto_profit.py Traceback (most recent call last): File "/home/Madmartigan/Trading/big_crypto_profit.py", line 3, in <module> from binance.client import Client ModuleNotFoundError: No module named 'binance.client'; 'binance' is not a package 07:56 ~ $

Are you sure that the "binance" package that you have installed is actually the module that you are trying to use? Perhaps you have installed something that has a similar name to what you want.

I have installed both 'binance' and 'python-binance' modules. "Client" is a part of python-binance package. The program runs on my PC without any problems.

Have you tried uninstalling the module called "binance"?

Yes, I tried. The result:

11:00 ~ $ python3.9 /home/Madmartigan/Trading/big_crypto_profit.py Traceback (most recent call last): File "/home/Madmartigan/Trading/big_crypto_profit.py", line 3, in <module> from binance.client import Client ModuleNotFoundError: No module named 'binance.client'; 'binance' is not a package 11:01 ~ $

What is the result of running this?

python3.9 -c "import binance; print(binance.__file__)"

The result is: /home/Madmartigan/.local/lib/python3.9/site-packages/binance.py

So, then you have not uninstalled the binance package in Python 3.9 and your import is trying to import from that.

Very wierd. I uninstalled binance package from the current project.

When you say "current project" do you mean a virtualenv, because the example with the error above does not appear to be in a virtualenv.

I mean the project in pycharm on my PC.

Unless you have some clever code to synchronise your package installs, your PyCharm installation is not going to affect what's on PythonAnywhere.

Ok, but where PyhonAnywhere look for imports? If it looks in virtualenv there is no such file as "binance"...

If you have a virtualenv activated, it will look in there. But the post you made earlier was not running in a virtualenv -- it was picking up a package called binance that you had installed into your account using pip3.9 install --user and then the name of the package.

And if I acitvate virutalenv then the program will start to work? How can I activate virtualenv?

When you activate virtualenv in the console pip relates to packages in that virtualenv so you install and uninstall packages in that vierualenv. Acrtivatio depends on how you created virtualenv. If you used mkvirtualenv you can use workon command to activate. If you want your web app to run in the vrualenv you have to configure it on the "Web" page.

The program is running at last!!! I installed python-binance package in virtualenv and it works! Thank you for support guys! It was very polite and usefull !

Glad to hear you made it work!

It worked but only for a few hours then stoped. If I tried to start from bash it returns:

bash: /home/Madmartigan/Trading/big_crypto_profit.py: Permission denied

What is the problem now?

Were you running it in a Python console in the editor before? The general rule is that all our consoles are not designed for long running jobs -- if you need one, you should consider using the Always-on task feature. If you want to run the script in the Bash console, you have to either make it executable and add so called shebang (string starting with "#!" at the beginning of the script that specifies the executable which should be used to run it, in your case that would be the python from a virtual env, I guess) OR to run it with Python like this: python /home/Madmartigan/Trading/big_crypto_profit.py (keep in mind that if you use a venv, you should activate it first, or provide the full path to the Python executable in the venv).

OK, thank you.

Hi, I have a similar problem. My python-binance package won't work with my virtual environment even when i'm installing in with the virtualenv. I also get "requirement already satisfied" along with the install every time installed.

Make sure that you're running your code in the virtualenv where you installed the package.

good day, i have a problem with cctx module, after saturday, with that module i can't connect to binance. can you help me wiith that problem. i run my code with python 3.9? fetch Response: binance GET https://api.binance.com/sapi/v1/capital/config/getall?timestamp=1670397903950&recvWindow=10000&signature=d012d305a3b51fed575591bdc85dd7544a38bf58f4d2cb8c40ab4b2934ebb3e7 451 ResponseHeaders: {'Server': 'CloudFront', 'Date': 'Wed, 07 Dec 2022 07:25:03 GMT', 'Content-Length': '224', 'Connection': 'keep-alive', 'Content-Type': 'application/json', 'X-Cache': 'Error from cloudfront', 'Via': '1.1 41bff299fdda9786ca0451ad8ebed114.cloudfront.net (CloudFront)', 'X-Amz-Cf-Pop': 'IAD55-P4', 'X-Amz-Cf-Id': 'guofk87sTLaFyyORvyzy-qh7n1tEpRRbgK1KAS32gG0Uj4AV01FM6w=='} ResponseBody: { "code": 0, "msg": "Service unavailable from a restricted location according to 'b. Eligibility' in https://www.binance.com/en/terms. Please contact customer service if you believe you received this message in error." } [ERROR] binance GET https://api.binance.com/sapi/v1/capital/config/getall?timestamp=1670397903950&recvWindow=10000&signature=d012d305a3b51fed575591bdc85dd7544a38bf58f4d2cb8c40ab4b2934ebb3e7

could you update cctx module, smth happened wrong. on my local mashine everything is fine.

This is likely because Binance no longer allows connections from US based servers. It's possible for us to migrate your account to https://eu.pythonanywhere.com/, which is hosted in Germany. As far as I'm aware, Binance still allows connections from there (though this could also change at any time). Please contact us at support@pythonanywhere.com if you would like to go ahead with this.

Tengo el mismo problema. como si la biblioteca estuviera mal. de hecho en el pc me pasó igual pero ejecuté el comando pip install --upgrade python-binance y funciona perfecto, claro está que solo en mi pc, aquí en la plataforma no funciona. Las otras bibliotecas como flask me funcionan perfectamente

el causante del error es este comando, no reconoce el módulo from binance.client import Client

That sounds like a different issue. How did you install the package on PythonAnywhere? Are you using a virtualenv? And where do you get the error saying that it's not installed?