I installed Flask-Paginate using pip, but when I try to import it I get ImportError: cannot import name 'Paginate'. How do I import this?
$ pip install -U flask-paginate
>>> from flask import Paginate
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Paginate'
The package also isn't recognized in PyCharm.
Don't import it from flask, it's not part of Flask. Import it from flask_paginate, the module you installed. It's also called Pagination.
The docs show how to import it (although they are using the deprecated flask.ext notation).
from flask_paginate import Pagination
Configure the project interpreter in PyCharm to point to the virtualenv you installed the package to.
As mentioned in flask-paginate docs:
from flask.ext.paginate import Pagination
However, flask.ext is removed. Use this instead:
from flask_paginate import Pagination
Related
I had trying a app using Flask.
I'm used my package UsefulDeveloperTools.
Its __init__.pylike this: (__init__.py)
"""
Useful Tools.
"""
import threads
import IDgenerator
And its directory is like this: (directories
.
\ __init__.py
\ threads.py
\ IDgenerator.py
And I pushed it in TestPyPI and installed it in my virtual environment used python3 -m pip install --upgrade --index-url https://test.pypi.org/simple/ --no-deps UsefulDeveloperTools.
And I have activated my environment,
and run following code use python3 main.py: (main.py)
import flask
from threading import Thread
import time
import random
import UsefulDeveloperTools # Error this
import logging
app=flask.Flask(__name__)
# unimportance
But python raised an error: (terminal)
(Blog) phao#phao-virtual-machine:~/桌面/pypoj/Blog$ python3 main.py
Traceback (most recent call last):
File "/home/phao/桌面/pypoj/Blog/main.py", line 5, in <module>
import UsefulDeveloperTools
File "/home/phao/桌面/pypoj/Blog/lib/python3.10/site-packages/UsefulDeveloperTools/__init__.py", line 5, in <module>
import threads
ModuleNotFoundError: No module named 'threads'
Why? What wronged? How can I finish it?
P.S. This is my packages in my environment: (terminal)
(Blog) phao#phao-virtual-machine:~/桌面/pypoj/Blog$ pip list
Package Version
-------------------- -------
click 8.1.3
Flask 2.2.2
itsdangerous 2.1.2
Jinja2 3.1.2
Markdown 3.4.1
MarkupSafe 2.1.1
pip 22.3.1
setuptools 59.6.0
UsefulDeveloperTools 0.2.2
Werkzeug 2.2.2
I looked on your repo and you are not following the packaging guide at all. You should reorganize your code in a proper file structure and set up eg. a pyproject.toml.
Python has an easy tutorial regarding packaging you can find here:
https://packaging.python.org/en/latest/tutorials/packaging-projects.html
Additionally your __init__.py is wrong. There are several options how you can put imports in your init file. The closes to what you attemptet would be to place a dot before the module names. But I don't know if that helps, before fixing the general package.
"""
Useful Tools.
"""
import .threads
import .IDgenerator
Check out this article for different options for init styles:
https://towardsdatascience.com/whats-init-for-me-d70a312da583
if you have made the module then keep it in the same directory as your file and run it.
Hi I thought this would be pretty straightforwards but I can't figure it out.
It can't find binance.websockets for whatever reason even though it can find binance.client which should be part of the same package?
import config
import os
from binance.client import Client
from twisted.internet import reactor
from binance.websockets import BinanceSocketManager
Running this import code gives this error
Traceback (most recent call last):
File "/home/lucho/Documents/cryptoAPIs/binance/importconfig.py", line 6, in <module>
from binance.websockets import BinanceSocketManager
ModuleNotFoundError: No module named 'binance.websockets
To get the library I installed with pip3
pip3 install python-binance
pip3 install binance-api
The BinanceSocketManager is no longer in the websockets file. Change your import to this:
from binance.streams import BinanceSocketManager
This will fix the issue
use this " pip install python-binance==0.7.9 "
If you look into the breaking changes on version 1.0.1 they mention they changes Websockets, so that is probably what you are hitting.
I would just reinstall the latest version "pip install python-binance" and use the up to date examples on their repo:
https://github.com/sammchardy/python-binance
I have some problems with the example of stable-baselines and look forward to your help.
The environment is set as:
Windows 10
spyder 3.6
tensorflow 1.4.0
gym 0.15.4
stable_baselines 2.8.0
However, I cannot import:
from stable_baselines.common import make_vec_env
The error is:
Traceback (most recent call last):
File "<ipython-input-96-9dcb30379014>", line 1, in <module>
from stable_baselines.common import make_vec_env
ImportError: cannot import name 'make_vec_env'
If this is the module we are talking about.
https://github.com/hill-a/stable-baselines
Seems like there was an issue that has been solved in 2.9.0:
https://github.com/araffin/rl-baselines-zoo/issues/51
Upgrade your stable-baselines:
pip install stable-baselines==2.9.0
And then it should be enough to use:
from stable_baselines.common.cmd_util import make_vec_env
I have this line in my code:
from twilio.rest import Client
But the result is:
Traceback (most recent call last):
File "send_sms.py", line 1, in <module>
from twilio.rest import Client
File "/Users/utilisateur/Downloads/twilio-6.17.0/twilio/rest/__init__.py", line 14, in <module>
from twilio.http.http_client import TwilioHttpClient
File "/Users/utilisateur/Downloads/twilio-6.17.0/twilio/http/http_client.py", line 1, in <module>
from requests import Request, Session, hooks
ImportError: No module named requests
What can I do ?
Whatever your environment is does not appear to have the requests library installed. Run pip install requests either from inside the environment in which this script is running (if you're not already, you should consider using virtualenv or something similar for this to avoid having to install Python packages globally as root).
Note that this likely wouldn't happen if you'd installed the Twilio library via pip, so I'm guessing you simply downloaded it and attempted to run it. If a Python library is in PyPi (which twilio is), you can install it via pip and have its dependencies automatically installed as well.
I installed anaconda to C:\Users\chris\Anaconda3. When I type conda list it verifies that I have BeautifulSoup4 installed.
However when I start C:\Users\chris\Anaconda3\python.exe and try to import BeautifulSoup it doesn't work:
>>> import BeautifulSoup
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'BeautifulSoup'
When I'm in the Anaconda Navigator it also lists the package but when I try to start base(root)/Open with python I can't import my package. Neither can Spyder that I installed.
What do I have to do, to fix this?
i'm sorry but maybe you need to import in this way ?
from bs4 import BeautifulSoup
docs