I am trying to learn NLP using BERT. While trying to import bert model and tokenizer in colab. I am facing the below error.
ImportError: cannot import name '_LazyModule' from 'transformers.file_utils' (/usr/local/lib/python3.7/dist-packages/transformers/file_utils.py)
Here is my code
!pip install transformers==4.11.3
from transformers import BertModel, BertTokenizer
import torch
In order to fix the error.
I tried to upgrade both transformers and torch.
I have tried the solution from the below link:This
Still i am unable to go forward.
Please assist.
Based on these links 1, 2
This should help -
pip install 'lightning-flash[text]' --upgrade
Since the code provided by you is not the cause of the error as it runs on Colab when I tried it hence this might be the culprit in your environment
Related
I have been trying to connect my MySQL database to Jupiter notebook. Could anyone take a look at it and maybe provide some feedback or improvements I could do? As connecting to a database is a first for me, and I would like to know if there is anything I could do to make it better
engine = db.create_engine("mysql+mysqlconnector://user:password#hostname/database")
df = pd.read_sql_query("select * from customer", engine)
engine.dispose()
df
Any feedback is appreciated! Thank you!
Install packages in CMD:
pip3 install mysqlclient
pip3 install pymysql
pip3 install ipython-sql
In the jupyter notebook:
import pandas as pd
import pymysql
connection=pymysql.connect(host='localhost',port=int(3306),user='root',password='PASSWORD',db='DBNAME')
df=pd.read_sql_query("SELECT * FROM 'TABLENAME' ",connection)
print(df)
Refer this article by Saeed Mohajeryami
Problem
We're trying to connect to Cloud Spanner via SQLAlchemy version 1.3.23 and python-spanner-sqlalchemy. Using Poetry for dependency management, sqlalchemy-spanner has been added like so (this is how the project was set up):
sqlalchemy = "~1.3"
sqlalchemy-spanner = { git="https://github.com/cloudspannerecosystem/python-spanner-sqlalchemy.git", tag="v0.1.0" }
When create_engine is called with
create_engine("spanner:///projects/my-project/instances/my-instance/databases/my-db")
I get the following error
class 'sqlalchemy.exc.NoSuchModuleError'>", "NoSuchModuleError(\"Can't load plugin: sqlalchemy.dialects:spanner\")
Attempts
Registry
I've tried adding (as seen in the conftest.py file in the python-spanner-sqlalchemy test package)
from sqlalchemy.dialects import registry
registry.register("spanner", "google.cloud.sqlalchemy_spanner", "SpannerDialect")
before create_engine is called, which leads to the following error:
class 'ModuleNotFoundError'>", "ModuleNotFoundError(\"No module named 'google.cloud.sqlalchemy_spanner'\")
This makes me think that the plugin dialect has not been correctly added since, in line 49 of setup.py, the connection for the dialect is made:
entry_points={
"sqlalchemy.dialects": [
"spanner = google.cloud.sqlalchemy_spanner:SpannerDialect"
]
},
Installing via python setup.py install
In the README for the spanner project, it says to clone the repo and install via python setup.py install. I performed this step, but am unsure how to import this into my current project or make my project aware of this library. I've never manually installed python packages before so, if anyone can provide any help here, I'd appreciate it.
What I did try:
install the library as per above
try to add the dependency via poetry : poetry add sqlalchemy-spanner. Got Could not find a matching version of package sqlalchemy-spanner
try to locate the library via pip : pip install sqlalchemy-spanner== which usually lists available package versions.
I'm not sure that either of the last 2 bullets actually check a local installation of a package. Not even really sure what I'm talking about here.
Update
So I was able to install the local version of python-spanner-sqlalchemy by using pip install /path/to/project, which works, but still having the same issues with loading the dialect.
I added an import for SpannerDialect in the code (in the Registry section) above with from google.cloud.sqlalchemy_spanner import SpannerDialect. PyCharm auto-completed this for me which indicates to me that the package is successfully installed and available. But I receive the ModuleNotFoundError for google.cloud.sqlalchemy_spanner when running.
I ran python in my project root directory and, from the repl, imported SpannerDialect with no errors.
Solution
To clarify, the solution #larkee provided worked regarding the updated repository URL.
As a note, we recently moved the repo from cloudspannerecosystem/python-spanner-sqlalchemy to googleapis/python-spanner-sqlalchemy.
I clarified why that worked in the comments to their answer
I have not tested the answer from #neondot42, but I have seen this brought up as well, so take a look there if you're having the same issue.
sorry for the late response. I was recently struggling with a similar problem. Sqlalchemy was unable to load the spanner dialect. I tried uninstalling and installing different versions with pip but nothing seemed to work.
At the end what did the trick was specifying the "driver" part of the database URL as "spanner" too. So the final URL looked like this:
spanner+spanner:///projects/project-id/instances/instance-id/databases/database-id
I am not entirely sure of why this appeared to be the solution for me, as all the documentation I could find on Google's end just showed that you could use only the "spanner:///..." to connect. Also I am not familiar with the inner workings of sqlalchemy and how it should detect other installed dialects. However, I hope this solution can help someone else.
I was able to replicate the error you are seeing by installing sqlalchemy but not having sqlalchemy-spanner installed at all:
pip install sqlalchemy==1.3
pip uninstall sqlalchemy-spanner
>>> from sqlalchemy import create_engine
>>> engine = create_engine(<url>)
sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects:spanner
After I install sqlalchemy-spanner I am able to use SQLAlchemy without issue:
pip install git+git://github.com/googleapis/python-spanner-sqlalchemy.git#v0.1.0
>>> from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String, inspect
>>> engine = create_engine(<url>)
>>> metadata = MetaData(bind=engine)
>>> table = Table(
... "TestTable",
... metadata,
... Column("user_id", Integer, primary_key=True),
... Column("user_name", String(16), nullable=False),
... )
>>> table.create()
>>> inspect(engine).get_table_names()
['TestTable']
>>>
Based on this, I think the issue is that sqlalchemy-spanner is not being installed. Unfortunately, I'm not familiar with Poetry for dependency management so I'm not sure exactly what is going wrong. As a note, we recently moved the repo from cloudspannerecosystem/python-spanner-sqlalchemy to googleapis/python-spanner-sqlalchemy. I am able to use either for the pip command but perhaps Poetry requires the newer one?
I have a Python script which imported 3 libraries:
import pymysql
import pandas as pd
from sqlalchemy import create_engine
I'm planning to run Python Shell on AWS Glue. Following this and this doc pages, I created a setup.py:
from setuptools import setup
setup(name="pylibmodule",
version="0.1",
packages=[],
install_requires=['sqlalchemy==1.3.9','pandas==0.25.3','pymysql==0.9.3']
)
I ran python setup.py bdist_wheel, put the resulting pylibmodule-0.1-py3-none-any.whl file into an S3 bucket, and then specified the bucket location in the Glue Job setting. When I ran the job script, it produced an error.
After an investigation, I found that I have sucessfully imported the pandas module, but failed to import sqlalchemy and pymysql.
ModuleNotFoundError: No module named 'sqlalchemy'
ModuleNotFoundError: No module named 'pymysql'
What am I doing wrong?
I ran the job again this morning without changing anything in the setting and the script. It suddenly works. I think the error I received last night was due to some cache residue on Glue's end.
Can somebody please help me loading the ipython module into jupyter notebooks?
ipython is a dependency for Jupyter, so it's already installed.
It looks like you're trying to import ipython widgets (ipywidgets) for use in Jupyter. To do this, in your shell (outside of Jupyter) install ipywidgets:
pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension
Then import widgets:
import ipywidgets as widgets
Read the docs to learn more about installing and using ipython widgets.
I believe that part of the problem is the capitalisation of the IPython package in your import statement:
try: import IPython.html.widgets
I don't know if that will get you everything you want, but that's probably the issue regarding your import.
I installed Pyautogui correctly and a I can import it from Python 3.5 but not from a script in IDLE Python 3.5.2
On the Shell the module pyautogui could not be found
I can't answer why an error is coming, but I may be able to solve your issue
Run this code on your Shell:
from subprocess import *
from sys import *
call([executable, "-m", "pip", "install", "pyautogui"])
Hope it helps :|