ImportError: cannot import name 'Timestamp' - python

I have ggplot successfully installed in my python 3.6.3 using the code below:
conda install -c conda-forge ggplot
But when I import it in my notebook using the code below, I get an error:
from ggplot import *
ImportError: cannot import name 'Timestamp'
I would appreciate any idea on how I can solve this problem.

I have encountered the same problem.
Please go to .../site-packages/ggplot/stats/smoothers.py and change
from pandas.lib import Timestamp
to
from pandas import Timestamp
and save.

#Liaoming999 is correct but adding more changes to resolve this problem:
Open file ../site-packages/ggplot/stats/smoothers.py
Change from pandas.lib import Timestamp to from pandas import Timestamp in line 4
Change pd.tslib.Timestamp to pd.Timestamp in line 14.
Save the file
Open file ../site-packages/ggplot/utils.py and goto line 81 and do the same as step 3. Thanks to #wmsmith for this tip.
p.s.: General advise is to use Anaconda or some Virtual env.

I encountered the same problem after upgrading to pandas 0.23 on a databricks server.
Had to come up with this command-line solution using the unix sed tool:
cd .../python/lib/python3.5/site-packages/ggplot/stats/
sed -i 's/pandas.lib/pandas/g' smoothers.py

I completely agree with #Srikar Appalaraju. Additionally, update the line 81 in utils.py (path is .../site-packages/ggplot/utils.py) from "pd.tslib.Timestamp" to "pd.Timestamp" to remove FutureWarning.

There has been little going on for a while in ggplot - maybe it'll change in the future, and the main project comes around.
In the meantime, instead of hacking the library (which is sometimes hard), you can use this friendly fork:
https://github.com/sushinoya/ggpy
Further reading:
https://github.com/yhat/ggpy/issues/654
Install using:
pip install git+https://github.com/sushinoya/ggpy
or:
pip install --user git+https://github.com/sushinoya/ggpy
(the latter may work in a shared server environment)
Caveats:
you'll need Git, and maybe a working compiler for Python extensions.

Related

Unable to import Pandas on Replit.com - Python

I'm unable to import pandas with import pandas as pd on replit.
I've already installed the package with pip install pandas and it can be seen in packages. I've successfully imported it to other projects on replit. Every time I try importing it into my code on this project, it gives me the following error:
Traceback (most recent call last):
File "main.py", line 1, in <module>
import pandas as pd
File "/home/runner/thing/venv/lib/python3.8/site-packages/pandas/__init__.py", line 16, in <module>
raise ImportError(
ImportError: Unable to import required dependencies:
numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.8 from "/home/runner/thing/venv/bin/python"
* The NumPy version is: "1.22.2"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: libz.so.1: cannot open shared object file: No such file or directory
You don't need to use pip to install packages on repl.it -- and in fact, you shouldn't! Using Nix derivations not only works better (as you're using their OS distro the way it's designed), but also keeps their storage costs low, by allowing packages to be used from a read-only, hash-addressed, shared store.
Binaries built for other distributions might assume that there will be libraries in /lib, /usr/lib, or the like, but that's not how NixOS works: Libraries will be in a path like /nix/store/<hash>-<packagename>-<version>/lib, and those paths get embedded into the executables that use those libraries.
The easiest thing to do here is to create a new bash repl, but to add a Python interpreter to it. (I suggest this instead of using a Python repl because the way they have their Python REPLs set up adds a bunch of extra tools that need to be reconfigured; a bash repl keeps it simple).
Create a new bash repl.
Click on the three-dots menu.
Select "Show Hidden Files".
Open the file named replit.nix
Edit the file by adding a Python interpreter with pandas, as follows:
{ pkgs }: {
deps = [
pkgs.bashInteractive
(pkgs.python38.withPackages (p: [p.pandas]))
];
}
...changing that to taste (as long as they're getting software from a channel that has binaries for Python 3.9 or 3.10, for example, you can change python38 to python39 or python310).
Click the "run" button
In the new shell that opens, run python, and see that you can import pandas without trouble.
If, after you add a Python file to your repl, you can also change the .replit hidden file to make it run that file automatically on startup. Note that on NixOS, you should use #!/usr/bin/env python as your shebang, as PATH lookups are essential.

Python package bar-chart-race 0.1.0: can't change separator thousands to dot

While using pandas with the python package: bar-chart-race 0.1.0, I can't seem to change the thousands seperator to German/Dutch style,
namely: 1.000,23 instead of 1,000.23
I tried changing the locale
import locale
locale.setlocale(locale.LC_ALL, 'deu_DEU')
'German_Germany.1252'
"{0:n}".format(x)
It gives this feedback:
TypeError: unsupported format string passed to DataFrame.format
I tried changing the style
df.head().style.format("{0:n}")
This works partly, because I see the df values correctly displayed in the first rows of output, but it won't implement the changes in the bart chart race graphical representation of the data...
Any help would be greatly appreciated, please be warned, this is my very first python project :) I'm an absolute newbie.
When you install barchartrace via pip or conda, this currently installs an old version which doesn't allow you to change the text formatting locale.
So, uninstall the version you currently have and install the latest version of bar chart race as follows in your command line. You do need to have git installed for this:
pip uninstall bar_chart_race
pip install git+https://github.com/dexplo/bar_chart_race
And then you set your locale so that you get comma separators for decimals. Working code example in Jupyter notebooks:
import bar_chart_race as bcr
import locale
locale.setlocale(locale.LC_NUMERIC, "de_DE")
df = bcr.load_dataset('covid19_tutorial')
bcr.bar_chart_race(
df=df,
filename=None,
bar_texttemplate='{x:n}',
tick_template='{x:n}',
)

Python does not import installed external library

This is a rather weird problem. I'm on Windows and using Anaconda for Python. There is a financial tool library called TA_lib (Technical Analysis Library). Since this library is not officially supported, I had to install a whl version and I got it from here.
After installation I was able to use it. But sometimes, when I start Anaconda and Spyder, the import talib command yields "Talib has no functiona as ..." and I cannot import and use it. When this happens, I follow these steps:
I close Anaconda and Spyder
I install the library again through Anaconda prompt (I see requirement already satisfied messge)
I restart Anaconda and Spyder
If I'm lucky, I can import talib after first try. If not, I have to repeat these steps for a couple of times. What might be wrong?
EDIT 1:
Now it's not working. Here is the error log:
import pandas as pd
import talib
import numpy as np
Traceback (most recent call last):
File "<ipython-input-2-a3bb601353da>", line 2, in <module>
import talib
File "C:\Users\ismetb\Desktop\AlgoritmikFinans\Classifier 11-12-2018 1830 v2\talib.py", line 90, in <module>
upperband, middleband, lowerband = talib.BBANDS(close, timeperiod=5, nbdevup=2, nbdevdn=2, matype=talib.MA_Type.T3)
AttributeError: module 'talib' has no attribute 'BBANDS'
There is a chance you've installed it wrong. Also consider that this is an unofficial library.
Make sure you installed the correct TA_lib for your Python version. What Python version are you using?
If it's 3.4, make sure you have downloaded the TA_lib cp34 for windows 64 bits or 32 bits. If it's another version, make sure you find the one appropriate to you.
Also another useful link to download TA_lib for 64bit is here.
I figured the problem. My Python file name was Talib_pure and then I renamed it to Talib. Since I import talib with import talib command, Python tried to import my own code isntead of talib library and therefore it got confused.
I renamed the file to ta_lib and now it works (so far at least).

Python ImportError - NUMPY MKL

I keep getting this error whenever I try running this code, if I can get some insight in what is going on that would be a great help, since I'm pretty new to this coding environment I would really appreciate some help. The code is this:
File "C:\Users\user\Desktop\Python\pythonsimulation.py", line 6, in
from scipy import *
File "C:\Python34\lib\site-packages\scipy__init__.py", line 61, in
from numpy._distributor_init import NUMPY_MKL # requires numpy+mkl
ImportError: cannot import name 'NUMPY_MKL'
Am I missing some package or module that python requires in order to run the code?
Reason:
This error indicates that numpy is missing NUMPY_MKL. This usually happens when you have installed scipy from .whl (Pre-compiled File). To resolve this.
Solution:
Download numpy+MKL wheel(.whl) from following link and install using pip.
http://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy
If you are using Jupyter, try restarting the kernel. please click Restart in Kernel menu.
Actually, there is no problem. Just need to restart the Jupyter and you will see it is working well.

Failed to import Numeric: No module named Numeric in F2PY

When I am trying to use F2PY, I'll get the error:
Failed to import Numeric: No module named Numeric
I know that numeric is dead and instead we should use numpy. But files:
/usr/local/lib/python2.7/dist-packages/f2py2e/src/fortranobject.h and
/usr/local/lib/python2.7/dist-packages/f2py2e/f2py2e.py both use the Numeric package. I tried to replace it with numpy, but I was not successful.
I used to use f2py without any problem, but after I formatted my computer and got a fresh copy of Ubuntu, I have this problem.
I also tried to use the option --2d-numpy for f2py like:
f2py -c --fcompiler=intel --2d-numpy -m processoutput processoutput.f
But it didn't work, and it is still looking for numpy.
Thank you for your help.
I ran into a similar situation using msys under Windows, and indeed I was trying to use an outdated version of f2py. The newer version is included with numpy (and doesn't need to be installed separately). And can be found in the site-packages/numpy/f2py directory. Although my setup is a bit different, I was able to compile from python using this script:
import numpy.f2py.f2py2e as f2py2e
import sys
sys.argv += "-c -m hello hello.f".split()
f2py2e.main()
You can download old versions of Numeric here: http://sourceforge.net/projects/numpy/files/Old%20Numeric/24.2/
If you install that, I think f2py will be satisfied.

Categories