KeyError('pandas._libs.interval') when opening a dataframe in Spyder - python

When I try to click on data frames in the Variable Explorer in Spyder, I get the following error:
This happens with all data frames (I tried making my own).
As a side note, functions like numpy.sum and .describe() don't output anything, but I'm unsure if this is related to the KeyError.
Thank you!

Add pandas to the packages option in setup.py module.
Here is the code snippet for setup.py
from setuptools import setup
APP = ['automating_finances0.py']
DATA_FILES = []
OPTIONS = {'packages': ['pandas']}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
If this not works please try reinstalling pandas from pip as
pip uninstall pandas
pip install pandas

Related

Py2App error: ModuleNotFoundError: No module named 'cmath' when using Pandas

I am trying to build a standalone app that utilises Pandas. This is my setup.py file:
from setuptools import setup
APP = ['MyApp.py']
DATA_FILES = ['full path to/chromedriver']
PKGS = ['pandas','matplotlib','selenium','xlrd']
OPTIONS = {'packages': PKGS, 'iconfile': 'MyApp_icon.icns'}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app','pandas','matplotlib','selenium','xlrd'],
)
The making of the *.app file goes smoothly, but when I try to run it, it gives me the following error:
...
import pandas._libs.testing as _testing
File "pandas/_libs/testing.pyx", line 1, in init pandas._libs.testing
ModuleNotFoundError: No module named 'cmath'
I tried to include ‘cmath’ in my list of PKGS and in setup_requires in the setup.py file, but when I tried to build the app using py2app it gave me the error:
distutils.errors.DistutilsError: Could not find suitable distribution for Requirement.parse('cmath')
I am stuck. I couldn't find anything useful online. cmath should be automatically included from what I have been reading. Any ideas on where is the problem and how can I fix it?
I think I have found a solution: downgrade to Python version 3.6.6.
See: python 3.6 module 'cmath' is not found
To uninstall Python I followed this process: https://www.macupdate.com/app/mac/5880/python/uninstall
Then I installed Python 3.6.6: https://www.python.org/downloads/release/python-366/
With Python 3.6.6, Py2App seem to work no problem and includes Pandas smoothly.
It seems that for some reasons cmath is not included in the latest versions of Python? I might be wrong. Please let me know what you think and if you have any questions.
P.S.: I am using MacOS (Mojave 10.14.6) and PyCharm.
I had a similar issue with py2app and cmath. I solved this by adding import cmath into the main script. (MyApp.py in your case) I think doing so may have the modulegraph to add the cmath library files.

Setup.py with py2app including pip packages

I built a keylogger in python and I used py2exe (version 0.13) to convert the python file to an exe. It worked perfectly, it included all the packages and everything.
I want my keylogger to come to mac also, so I tried to use py2app. I followed TheBlackBerryChannels tutorial. It was pretty good explaining everything but it didn't show how to install external packages that are installed from pip. Becuase I use the from pynput.keyboard import Key, Listener
import os
import datetime
from pathlib import Path
packages from pip.
In the full setup.py file this is what I have:
from setuptools import setup
APP = ['KeyLoggingMac.py']
OPTIONS = {
# 'iconfile':'logoapp.icns',
'argv_emulation': True,
'packages': ['pynput']
}
setup(
app=APP,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
What am I doing wrong? It doesn't include the pynput package, I figured that it would auto-include the os, datetime, and pathLib modules but why doesn't it include the pynput?
For simplicity sake in your main file import it like this:
from pynput import keyboard
Then in your setup file use 'includes' in OPTIONS, note that I also added the data file test.txt to write the key presses to a file:
from setuptools import setup
APP = ['TEST.py']
DATA_FILES = ['test.txt']
OPTIONS = {'includes': ['pynput']}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Then from your venv run py2app with the terminal command:
python setup.py py2app
You can also use py2applet to generate setup.py files but I find it never works properly.
py2applet --make-setup FILENAME.py
You will also need to give the app permission to access your global keyboard events. This is done in Preferences > Security & Privacy > Privacy
Up to Mojave you want the Accessibility tab then add your app in there, on Catalina you want Input Monitoring.
This works for me.

py2app can't import pandas

I am trying to create a standalone app from a python 2.7 script I have run many times and so I followed a tutorial and created the setup file that looks like this:
from setuptools import setup
APP = ['scrapeMaps.py']
DATA_FILES = ['export.csv']
OPTIONS = {'argv_emulation': True,}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
When I locate the scrapeMaps file (the one that was created when I did $ python setup.py py2app -A) and try to run it, I get an error saying
import pandas as pd
ImportError: No module named pandas
I have used pandas numerous times and it works perfectly.
I have tried adding
PKGS = ['pandas']
OPTIONS = {'argv_emulation': True,
'packages' : PKGS,}
without success. Also, none of my other imports are working (if I remove import pandas, I will get an error at import selenium)
Also tried:
$ python setup.py py2app --packages=pandas
but I get a huge syntax error.
Thanks

py2app ImportError with watchdog

I am attempting to use py2app to bundle a small Python app that I've made in Python 2.7 on Mac. My app uses the Watchdog library, which is imported at the top of my main file:
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
When running my program, these import statements work just fine, and the program works as expected. However, after running py2app, launching the bundled application generates the following error:
ImportError: No module named watchdog.observers
At first I thought it was something to do with the observers module being nested inside watchdog, but to test that, I added the line
import watchdog
to the top of my program, and then upon running the app, got the error
ImportError: No module named watchdog
so it seems that it actually can't find the watchdog package, for some reason.
I tried manually adding the watchdog package using py2app's --packages option:
$ python setup.py py2app --packages watchdog
but it had no effect.
My unbundled Python program runs just fine from the command line; other downloaded modules I've imported are giving no errors; and I have successfully bundled a simple "Hello World!" app using py2app, so I believe my setup is correct.
But I'm kind of out of ideas for how to get py2app to find the watchdog package. Any ideas or help would be greatly appreciated.
Edit: Here is the text of my setup.py, as generated by py2applet. I haven't modified it.
from setuptools import setup
APP = ['watcher.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
Try manually including the desired packages in the setup.py file:
from setuptools import setup
APP = ['watcher.py']
DATA_FILES = []
PKGS = ['watchdog', /*whatever other packages you want to include*/]
OPTIONS = {
'argv_emulation': True,
'packages' : PKGS,
}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
I had installed watchdog 0.5.4, a very old version as it turns out, and got the same error. The error was fixed after upgrading it to 0.8.3:
pip install watchdog --upgrade
Your problem generally indicates that the package (in your case "watchdog", or one of its dependencies) isn't installed, or at least not in a location that py2app expects to find packages.
Do you use the same python command for running py2app as for running the script from the command-line? What is the message of the ImportError you're getting (both when importing "watchdog" and importing "watchdog.observers"?
The (way too long) output of py2app should also mention that it cannot find some packages, and which ones.
As alluded to in one of the answers py2app does not seem to search the same set of paths that are used by the python interpreter, so you need to copy the python library to one of those locations.
For example I've got the MacPorts version of Python installed and found that when I had a module installed in /Library/Python/2.7/site-packages/ py2app wasn't finding it, but it would find it when I copied it into /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages. So to copy it over run :
sudo cp /Library/Python/2.7/site-packages/thatmodule.so /opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/
Then run the py2applet script again and build the app to check. If it's elsewhere you can do a search for all site-packages locations using Spotlight's command line interface:
mdfind -name site-packages

py2app setup.py usage question

Ok so I'm trying to use py2app to generate a distribution for my project. I'm still not sure I get the hang of it tho. So my setup.py looks like this:
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
import setuptools
PACKAGES = ['sqlalchemy.dialects.sqlite']
MODULES = ['sqlite3']
APP = ['tvb/interfaces/web/run.py']
OPTIONS = {'argv_emulation': True,
'packages': PACKAGES ,
'includes' : MODULES }
DATA_FILES = []
setup(
app=APP,
data_files=DATA_FILES,
packages = setuptools.find_packages(),
include_package_data=True,
options={'py2app': OPTIONS},
setup_requires=['py2app', "pyopengl", "cherrypy", "sqlalchemy", "simplejson",
"formencode", "genshi", "quantities","numpy", "scipy",
"numexpr", "nibabel", "cfflib", "mdp", "apscheduler",
"scikits.learn"]
)
So my first question would be: What should I include in my MODULES for py2app here? Does py2app know to scan for the things in setup_requires and include them or do I need to add some entries for them in MODULES ?
Another problem is that I'm getting an: sqlalchemy.exc.ArgumentError: Could not determine dialect for 'sqlite' when trying to run my app. After lots of googling I only saw that for py2exe you need to include the sqlalchemy.dialects.sqlite as a package but it doesn't seem to work for me. Am I missing something here?
The last one is that I'm getting a: malformed object (load command 3 cmdsize not a multiple of 8) just before the python setup.py py2app. Is this normal?
Regards,
Bogdan
Well seems I got the whole thing wrong.
'includes' : ['sqlalchemy.dialects.sqlite']
Instead of packages, and that seems to have done the trick.

Categories

Resources