No module named 'bankdate'(How to import just .py??) - python

Sorry that I have no idea how to describe this situation. The bigger package I like to install is "finance" (http://pydoc.net/finance/0.2502/finance.bankdate/). I downloaded it and unzipped to install using python setup.py install.
However, I cannot resolve importing another sub-module
bankdate(.py)
When I use finance module, there comes the error message, "ImportError: No module named 'bankdate'.(It is required in "__init__.py" under finance.) bankdate.py seems to be file under finance folder. How could I install "bankdate"?? Does anybody help me with this??
Thank you~!
cf) pip install bankdate, easy_install bankdate don't work in this case.

I do not know if you are working with Linux or Windows. But it would be a good start checking if the package was installed properly. You could use the following code to check installed packages and its versions:
import pip
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
for i in installed_packages])
print(installed_packages_list)
By doing so packages installed using both setuptools and pip will appear in a list below. If your package does not appear in the list there you have, it was not installed.
Neverhteless try to import the module usign this:
from finance import bankdate
And see if the error continue. Hope it helps.

you can use pip install finance or you can download .whl file use pip intsall .whl
you can try

Related

Why do I get 'No module named 'currency-symbols' when importing xls2xlsx, even though 'pip install currency-symbols' returns requirement satisfied?

My IDE is Spyder and the distribution I am using is miniconda. I use pip install in the anaconda prompt window (as I usually do).
'pip install xls2xlsx' seems to run fine and install the package.
When I try 'from xls2xlsx import XLS2XLSX' I get the following error:
ModuleNotFoundError: No module named 'currency-symbols'
If I try 'pip install currency-symbols' , I get:
'Requirement already satisfied: currency-symbols in c:\users\user\miniconda3\lib\site-packages (2.0.2) '
I can see both directories in the site-packages directory.
So I had the same or very similar problem, my trace-back said it could not import currency_symbols. I found that the module it was trying to import was the constants from that package. So I went into the py file where xls2xlsx had the issue
"htmlxls2xlsx.py" my traceback said line 40..
currency_symbols_constants =
importlib.import_module('currency-symbols.constants')
I noticed this was part of an 'exception' so I fixed line 37 from import currency_symbols.constants as currency_symbols_constants to import currency_symbols._constants as currency_symbols_constants
Now it imports just fine.
I also had version 2.0.2 of currency-symbols installed, but my working host was using 2.0.1. I discovered that if you install 2.0.1, the issue did not occur.
pip3 install -Iv currency-symbols==2.0.1

Getting module 'google.protobuf.descriptor_pool' has no attribute 'Default' in my python script

I am new to python and was using a python script written by someone else. I was running it fine in a different PC. Just had to install coupe of packages including pip3, google-cloud, google-cloud-bigquery and pandas.
Now when I installed the same packages on a different PC, I am unable to run the script. It is showed the following error first:
module = 'google.protobuf.descriptor_pb2' TypeError: expected bytes, Descriptor found
However, when In purged/re-installed/updated packages and also added protobuf3 and protobuf-py3 package, The error has been updated to the following message:
from google.cloud import bigquery
File "/home/mobeen/.local/lib/python3.6/site-packages/google/cloud/bigquery/__init__.py", line 35, in <module>
from google.cloud.bigquery.client import Client
File "/home/mobeen/.local/lib/python3.6/site-packages/google/cloud/bigquery/client.py", line 50, in <module>
import google.cloud._helpers
File "/home/mobeen/.local/lib/python3.6/site-packages/google/cloud/_helpers.py", line 33, in <module>
from google.protobuf import duration_pb2
File "/home/mobeen/.local/lib/python3.6/site-packages/google/protobuf/duration_pb2.py", line 8, in <module>
from google.protobuf import symbol_database as _symbol_database
File "/home/mobeen/.local/lib/python3.6/site-packages/google/protobuf/symbol_database.py", line 193, in <module>
_DEFAULT = SymbolDatabase(pool=descriptor_pool.Default())
AttributeError: module 'google.protobuf.descriptor_pool' has no attribute 'Default'
.Any help or leads in this will be appreciated
I solved the problem by uninstalling protobuf:
pip3 uninstall protobuf
pip3 uninstall python3-protobuf
NB: You should repeat this command until you get a message that there is no package named protobuf.
After that execute:
pip3 install protobuf
Install just the protobuf , don't install python3-protobuf
Hope this solution can help you.
I solved it by first executing twice
pip3 uninstall protobuf
The second time the terminal returned
Found existing installation: protobuf 3.6.1
Not uninstalling protobuf at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'protobuf'. No files were found to uninstall.
Then I removed protobuf manually
sudo rm -r /usr/lib/python3/dist-packages/google/protobuf*
sudo rm -r /usr/lib/python3/dist-packages/protobuf*
And finally I executed
pip3 install --upgrade protobuf
And the problem was solved
Did you try this too?
"I solved the problem of showed Attribute Error: 'module' object has no attribute 'Default' when import tensorflow after installed by delete redundant protobuf file.
The reason is some google/protobuf/descriptor_pool.py do not have a 'Default' defined. This usually happened at old version of protobuf so I upgraded successfully, but problem not solved. And by checking PATH and search about 'google/protobuf', I found it existed in both "/usr/local/lib/python2.7/dist-packages/google/protobuf/" and "/usr/lib/python2.7/dist-packages/google/protobuf/". Previous one have attribute 'Default' but the second one not.
I tried import google.protobuf and google.protobuf.file, It shows '/usr/lib/python2.7/dist-packages/google/protobuf/init.pyc'. I deleted /usr/lib/python2.7/dist-packages/google/protobuf and tried to import tensorflow, worked."
Actually I've ran into a similar case, we had 2 packages installed protobuf and python3-protobuf. I actually dont know the root cause for this but apparently when you do that:
pip install protobuf
pip install python3-protobuf
that error you described is happening, looks like it gives you some different version, like those two packages have overlapping files, and they override each other or something.
the solution for me was simply to reverse the installation order (make sure to uninstall them both first):
pip install python3-protobuf
pip install protobuf
or just
pip install python3-protobuf protobuf
hope this helps anyone here.
The reason can be that the interpreter that you are using to run the python programm uses the previous version of google.protobuf
You can assure it to run in the interpreter
>>> import google.protobuf
>>> print google.protobuf.__version__
Then compare it running in the terminal
$pip show protobuf
If the versions are different that's the reason
So I suggest deleting this package right from the python interpreter console
>>> pip uninstall protobuf -y
After you can even install the package right from the python console
>>> pip install protobuf
After that you good to go ✌️

Importing the Attention package in Keras gives ModuleNotFoundError: No module named 'attention'

As part of my imports, I am importing the AttentionLayer package as follows:
from attention import AttentionLayer
I get the following error:
ModuleNotFoundError: No module named 'attention'
I figured this might be because I need to pip install it so I tried based on other answers I found online a few pip installs I tried were:
pip install AttentionLayer
pip install Attention
pip install keras-self-attention
All 3 of those give me:
Could not find a version that satisfies the requirement keras-self-attention (from versions: ) No Matching distribution found for....
Why am I not getting it to work and how can I fix it?
I have a suspicion that it might be related to setting the pythonpath but I do not have admin rights to edit this at work.
Thank you.
try using the name keras-attention:
pip install keras-attention
you can search pip for packages like this:
pip search attention
keras-attention (1.0.0) - Attention Mechanism Implementations for NLP via Keras
.
.
.
(other stuff)
Try this:
Install keras-self-attention: pip install keras-self-attention
Import SeqSelfAttention: from keras_self_attention import SeqSelfAttention
It worked for me!
I am working on google collab, this code worked for me on Feb 2021
pip install keras-self-attention
It's because You didn't have attention module, go to this link https://github.com/thushv89/attention_keras/blob/master/layers/attention.py and use this attention module. Regards.

Checking if a package is installed specifically via pip

Checking if a particular package is available from within Python can be done via
try:
import requests
except ImportError:
available = False
else:
available = True
Additionally, I would like to know if the respective package has been installed with pip (and can hence been updated with pip install -U package_name).
Any hints?
I believe one way to figure out if a project has been installed by pip is by looking at the content of the INSTALLER text file in the distribution's dist-info directory for this project. With pkg_resources from setuptools this can be done programmatically like the following (error checking omitted):
import pkg_resources
pkg_resources.get_distribution('requests').get_metadata('INSTALLER')
This would return pip\n, in case requests was indeed installed by pip.
You said subprocess.call() is allowed, so
available = not(subprocess.call(["pip", "show", "requests"]))

No module named owslib.wmts

I installed owslib through command line by:
pip install owslib
and it worked. But for some reason I am getting an error saying: No module named owslib.wmts . What do you think would be causing this? I tried installing Anaconda, I've rebooted a few times, and when I run this script:
import pip
installed_packages = pip.get_installed_distributions()
installed_packages_list = sorted(["%s==%s" % (i.key, i.version)
for i in installed_packages])
print(installed_packages_list)
it shows me the installed modules like this:
['nose==1.3.7', 'numpy==1.11.1', 'overpy==0.3.1', 'owslib==0.11.2',
'pip==8.1.1', 'pyproj==1.9.5.1', 'python-dateutil==2.5.3',
'pytz==2016.6.1', 'requests==2.11.1', 'setuptools==20.10.1', 'six==1.10.0']
any ideas?
You can try
pip install owslib.wmts
Otherwise there might be a problem within the module. Look at this website it has the documentation for owslib documentation
So I am 99% sure this is a problem on my work machine. I have found a workaround by using the Anaconda terminal instead of windows cmd line.

Categories

Resources