I'm trying to use the xls2xlsx module to convert several .xls files to .xlsx format, but I get the following error message:
ModuleNotFoundError: No module named 'currency-symbols'
The code:
import os
from xls2xlsx import XLS2XLSX
path = r'./ammcfiles'
p = os.listdir(path)
for f in p:
if f.endswith('.xlsx'):
x2x = XLS2XLSX(f)
x2x.to_xlsx(f)
I tried pip installing the module, but it didn't solve the problem.
My Python version is 3.10.4.
Note: More of the stacktrace would have been helpful to see the full issue.
Had a similar issue with a script that was developed and previously run with Python 3.6.
Running the script in Python 3.10 returned the following error:
Traceback (most recent call last):
File "<virtual env>/lib/python3.10/site-packages/xls2xlsx/htmlxls2xlsx.py", line 37, in
import currency_symbols.constants as currency_symbols_constant
ModuleNotFoundError: No module named 'currency_symbols.constants'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/script/./script.py", line 20, in
from xls2xlsx import XLS2XLSX
File "<virtual env>/lib/python3.10/site-packages/xls2xlsx/init.py", line 3, in
from .htmlxls2xlsx import HTMLXLS2XLSX
File "<virtual env>/lib/python3.10/site-packages/xls2xlsx/htmlxls2xlsx.py", line 40, in
currency_symbols_constants = importlib.import_module('currency-symbols.constants')
File "/usr/lib/python3.10/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'currency-symbols'
Investigation
Ensure the packages are installed
python -m pip install xls2xlsx currency-symbols
Lines 36-40 of <virtual env>/lib/python3.10/site-packages/xls2xlsx/htmlxls2xlsx.py
try:
import currency_symbols.constants as currency_symbols_constants
except Exception:
import importlib
currency_symbols_constants = importlib.import_module('currency-symbols.constants')
This code seems to be responsible for loading the currency-symbols module regardless of the Python version and by extension the module version.
Therefore, the original error was received because both import attempts failed.
<virtual env>/lib/python3.10/site-packages/currency_symbols/ contains the file
_constants.py and not constants.py.
Note the folder is currency_symbols and not currency-symbols, underscore (_) vs dash (-). Therefore, htmlxls2xlsx.py is using the new currency-symbols module name currency_symbols but not the new name of the constants sub module _constants
Fix
Edit htmlxls2xlsx.py to use _constants.py
try:
import currency_symbols._constants as currency_symbols_constants
This fixes the import and usage issues.
As Yuli L mentioned, inside the htmlxls2xlsx.py which is in xls2xlsx module directory I found next:
import currency_symbols.constants as currency_symbols_constants
And change by (take care with typos):
import currency_symbols._constants as currency_symbols_constants
Related
I am getting the error: "ModuleNotFoundError: No module named 'kucoin.client'; 'kucoin' is not a package" when running the code underneath. I did pip install like in the documentation here: hhttps://python-kucoin.readthedocs.io/en/latest/ . What is going wrong?
import api_KuCoin
Xkey = api_KuCoin.Pkey
Ykey = api_KuCoin.Skey
Zkey = api_KuCoin.Dkey
client = Client(api_key=Xkey, api_secret=Ykey, api_passphrase=Zkey)```
Traceback (most recent call last):
File "d:\Crypto\kucooin.py", line 1, in <module>
from kucoin.client import Client
ModuleNotFoundError: No module named 'kucoin.client'
This error: ModuleNotFoundError: No module named 'kucoin.client'; 'kucoin' is not a package may also occur if you have named the main program file you created as kucoin.py and try to run it as python kucoin.py or another file has the name kucoin.py in the same folder from which you run your program. Python will consider your program file as a module and try to find something in it that is naturally not in it. About where Python is looking for modules, see sys.path.
In this case, rename your program file so that its name does not equal with the name of the imported module.
I have uninstalled and re-installed the latest version of datatable from the repo
16:42:49/seirdc2.March8.in $sudo pip3 install 'datatable==0.10.1'
Successfully installed datatable-0.10.1
Let's see the version:
import datatable as dt
print(f'datatable version={dt.__version__}')
Um oops !
Traceback (most recent call last):
File "/git/corona/python/pointr/experiments/python/datatable.py", line 18, in <module>
import datatable as dt
File "/git/corona/python/pointr/experiments/python/datatable.py", line 19, in <module>
print(f'datatable version={dt.__version__}')
AttributeError: module 'datatable' has no attribute '__version__'
But why?
Note: I have seen other strangeness with this package: e.g. not finding Frame - though not consistently.
It appears that the problem has nothing to do with datatable. Look at the traceback:
Traceback (most recent call last):
File "/git/corona/python/pointr/experiments/python/datatable.py", line 18, in <module>
import datatable as dt
File "/git/corona/python/pointr/experiments/python/datatable.py", line 19, in <module>
print(f'datatable version={dt.__version__}')
AttributeError: module 'datatable' has no attribute '__version__'
Doesn't it strike you as suspicious that you have line 18 "calling" line 19? I mean, how could it be? Here's how:
When you name your script datatable.py and then do import datatable, then instead of importing the actual module from site-packages, it imports the "module" datatable.py instead. Basically, the file imports itself. And the way python manages imports, is that it creates a "stub" module in the sys.modules first (in order to prevent infinite recursions during imports). In your case, the module tries to import itself, so the stub module is fetched instead -- and then when you try to print its __version__ variable, turns out it doesn't exist.
You can verify this by printing dt.__file__ instead, which should show the location of the file that is being imported.
Needless to say, all this is not specific to datatable in any way; for example if you created a file numpy.py and then tried to import numpy, you'd run into same problems.
I am trying to add an external python library from a third party software into Spyder so I can work with it. I have already tried the following:
Adding library path containing .py files to Tools>PYTHONPATH manager
Synchronizing the path
Updating module names list through Tools>Update Module names list
However, when I try to import modules from this library I get two types of errors:
import easy
Traceback (most recent call last):
File "<ipython-input-2-685519d35f15>", line 1, in <module>
import easy
File "C:\Program Files (x86)\Plaxis\PLAXIS 2D\plxscripting\easy.py", line 24, in <module>
from .server import Server, InputProcessor
ValueError: Attempted relative import in non-package
The second type of error as follows:
from plxscripting.easy import *
Traceback (most recent call last):
File "<ipython-input-1-a40c101d3bb0>", line 1, in <module>
from plxscripting.easy import *
ImportError: No module named plxscripting.easy
I don't understand why Spyder is not recognizing these libraries. The path has been added and shows up on the manager. What constitutes a python module? Is it not just the .py file with module name prefix? Is not the path sufficient to work with the library through the IDE?
I installed django python module on my machine, and used it like this
a.py:
import django.core
...
then, I created an new file django.py in the same folder of file a.py, and re-run a.py, it throw import error, since it just imported my local django.py
File "a.py", line 1, in <module>
import django.core
ImportError: No module named core
So, how to distinguish them when importing python module?
You can use the imp module to import your script directly from a local path:
mymodule = imp.load_source('mymodule', 'django.py')
You can then use mymodule as if you had imported it normally.
Use caution, however; the python import internals must be subverted responsibly.
You could temporarily remove the current directory from PYTHONPATH:
$ python -c'import numpy.core' # works
$ touch numpy.py # add conflicting module
$ python -c'import numpy.core' # it fails now
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 2218, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: No module named 'numpy.core'; 'numpy' is not a package
$ python -c'import sys; sys.path.remove(""); import numpy.core' # works again
Needless to say, you should use such hacks sparingly if at all -- avoid manipulating sys.path manually. Rename your local module, to avoid the conflict instead (move it inside a package at least e.g.: your_package/numpy.py).
When I try to run the following Python 3.3 code on OS X 10.8 in PyCharm 2.7 (or run the .py file with the Python 3.3/2.7.3 launcher):
import urllib.request
f = urllib.request.urlopen('http://www.python.org/')
print(f.read(300))
I get the following error message:
/System/Library/Frameworks/Python.framework/Versions/3.3/bin/python3 /Users/username/PycharmProjects/urllib/urllib.py
Traceback (most recent call last):
File "<frozen importlib._bootstrap>", line 1512, in _find_and_load_unlocked
AttributeError: 'module' object has no attribute '__path__'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/Users/username/PycharmProjects/urllib/urllib.py", line 3, in <module>
import urllib.request
File "/Users/username/PycharmProjects/urllib/urllib.py", line 3, in <module>
import urllib.request
ImportError: No module named 'urllib.request'; urllib is not a package
Process finished with exit code 1
The only way I can succesfully run the code is via the Python shell.
Any ideas on how to solve this?
Thanks.
I changed the filename to url.py, now it succesfully executes in PyCharm.
But when executing the file via Python Launcher 3.3 it gives me the following error:
File "/Users/username/PycharmProjects/urllib/url.py", line 3, in <module>
import urllib.request
ImportError: No module named request
Why is the code running fine in PyCharm (3.3) but giving me an error when launched with Python Launcher (3.3)?
You named your file urllib, it is shadowing the standard library package. Rename your file.
In mac, VSCode is using Python 2. If you print urllib module, you will find out that this module is for Python 2.
So, I added one comment to choose Python version:
#!/usr/local/bin/python3
from urllib.request import urlopen
In my case, it waw solved activating in command palette (shift+commant+p) Linting: Enable Linting: on and in VMStudio Settings (Preferences => Settings) select flake8 in Python:linter => Linter to use as flake8.