Python Integration problem - Eviews 11 Enterprise Edition

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Jason, EViews Moderator, EViews Matt

marend
Posts: 13
Joined: Fri Jul 19, 2013 12:20 pm

Python Integration problem - Eviews 11 Enterprise Edition

Postby marend » Tue May 07, 2019 8:05 am

Hello, I am trying to use Python in Eviews. I followed the instructions using xopen(p), which opens a python command console, but then when trying to import the pandas package ( import pandas as pd) I get the following error message:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))

And when I try to import the numpy package (import numpy as np) I get the following error message:

Unknown Python error

Can you please help me to solve this problem.

Thank you,

EViews Steve
EViews Developer
Posts: 788
Joined: Tue Sep 16, 2008 3:00 pm
Location: Irvine, CA

Re: Python Integration problem - Eviews 11 Enterprise Edition

Postby EViews Steve » Tue May 07, 2019 2:34 pm

The first thing to do when you encounter an error caused by running a Python command is to run it directly within Python to see if it's caused by EViews or not. If the command also generates an error within Python directly, then it's not an EViews problem.

That said, this specific error is caused by not having the Pandas & Numpy library installed in your Python environment. Without the libraries pre-installed, you can't import it.

EViews 11 will not install any Python libraries for you. You have to do this yourself. EViews does try to use both Pandas and Numpy if it detects it, but if it doesn't, then EViews will default to using base Python data types when pushing object data.

Here's a page describing how to install Numpy into your Python environment.
Here's the page describing how to install Pandas.

We also wrote a blog post that describes how to install the these libraries in your generic Python environment. It's basically just using the PIP command (run this command OUTSIDE of python):

Code: Select all

pip install numpy
pip install pandas

If you are using a conda python environment (e.g. Anaconda), you should use the CONDA command instead of PIP (run these in a Conda command prompt):

Code: Select all

conda install numpy
conda install pandas


Once you have successfully installed these libraries, then you can run the Python command:

Code: Select all

import numpy as np

both within Python directly or from EViews.

Steve

marend
Posts: 13
Joined: Fri Jul 19, 2013 12:20 pm

Re: Python Integration problem - Eviews 11 Enterprise Edition

Postby marend » Tue May 07, 2019 3:23 pm

I installed numpy and pandas in the home directory and changed in Eviews the COM ProgID for Python Home Path to the home directory (C:\Users\HP Z800 in my case), but I still have the same problem, with the following error message:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\HP Z800\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))

Please help.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13294
Joined: Tue Sep 16, 2008 5:38 pm

Re: Python Integration problem - Eviews 11 Enterprise Edition

Postby EViews Gareth » Tue May 07, 2019 4:37 pm

Can you run

Code: Select all

import pandas as pd

from within Python (not inside EViews)?
Follow us on Twitter @IHSEViews

marend
Posts: 13
Joined: Fri Jul 19, 2013 12:20 pm

Re: Python Integration problem - Eviews 11 Enterprise Edition

Postby marend » Tue May 07, 2019 5:20 pm

I have never had any problem in working with Pandas and Numpy, actually tboth packages work perfectrly in Spyder Jupyternotebook.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13294
Joined: Tue Sep 16, 2008 5:38 pm

Re: Python Integration problem - Eviews 11 Enterprise Edition

Postby EViews Gareth » Tue May 07, 2019 5:53 pm

Sure, but can you run that command from within Python?
Follow us on Twitter @IHSEViews

marend
Posts: 13
Joined: Fri Jul 19, 2013 12:20 pm

Re: Python Integration problem - Eviews 11 Enterprise Edition

Postby marend » Tue May 07, 2019 8:41 pm

I was able to do it. I had to reinstall Pyhton in my computer and create a Path in a new location (I thought it might had been an issue of whitespaces in the folder where the packages were installed). I am not certain of what it was, but know is working. Thank you

tinadl
Posts: 3
Joined: Tue Nov 30, 2021 12:17 pm

Re: Python Integration problem - Eviews 11 Enterprise Edition

Postby tinadl » Tue Nov 30, 2021 2:56 pm

I have 2 questions on this topics:
1. I'm currently having the same problem, and like @marend mentioned, I cannot import numpy or pandas in EViews, while I am able to do the same in Anaconda/Python. I tried re-installing Anaconda in a different location, but to no avail. (Not sure if I know how to solve for white spaces, as @marend mentioned)

2. Sometimes, I am not even able to open the python console, that is, xopen(p) shows an error saying failed to initialize PyConn. Is there any step I'm missing before I attempt to open the console? (My colleagues also cant seem to open the console, all of whom have at least a basic python version in their machine).



Ps, the exact error for the import that I'm seeing is given below:

******For "import numpy as np"******
Python returned an error:

Traceback (most recent call last):
File "C:\Users\--\Anaconda3\lib\site-packages\numpy\core
\__init__.py", line 22, in <module>
from . import multiarray
File "C:\Users\--\Anaconda3\lib\site-packages\numpy\core
\multiarray.py", line 12, in <module>
from . import overrides.

*****For "import pandas as pd"******
Python returned an error:

Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Users\--\Anaconda3\lib\site-packages\pandas\__init__.
py", line 16, in <module>
raise ImportError(.

Thank you very much!

EViews Steve
EViews Developer
Posts: 788
Joined: Tue Sep 16, 2008 3:00 pm
Location: Irvine, CA

Re: Python Integration problem - Eviews 11 Enterprise Edition

Postby EViews Steve » Tue Nov 30, 2021 3:15 pm

What version and build date of EViews are you using? Also, what version of Python did you install? For both questions, please also provide whether the software is 32-bit or 64-bit.

tinadl
Posts: 3
Joined: Tue Nov 30, 2021 12:17 pm

Re: Python Integration problem - Eviews 11 Enterprise Edition

Postby tinadl » Wed Dec 01, 2021 11:04 am

I'm using EViews 12. Python version is 3.9 and software is 64-bit for both.

EViews Steve
EViews Developer
Posts: 788
Joined: Tue Sep 16, 2008 3:00 pm
Location: Irvine, CA

Re: Python Integration problem - Eviews 11 Enterprise Edition

Postby EViews Steve » Wed Dec 01, 2021 11:56 am

Ok, using EViews 12, I tried importing numpy from a conda controlled python installation using Python v3.9.7 and I didn't have any issues on my system.
numpy.png
numpy.png (15.98 KiB) Viewed 22592 times

I would suggest you try creating and using a new Python 3.9 conda environment to see if that resolves your issue. Try the following:



Re-Register EViews Components
First, if you have local admin rights, make sure you run REGCOMPONENTS from within EViews (type it into the command window) and then click the "Yes (All)" button to re-register everything. This will make sure the EViews Python components are registered from that same EViews program folder.

Verify your EViews program folder has the following Python files
python_files.png
python_files.png (42.47 KiB) Viewed 22592 times
Make sure the file sizes match from my screenshot above. If any of these files are missing, re-install EViews 12.

Create a new Anaconda Environment
Open the Anaconda prompt, then type in the following command to create a new Python 3.9 environment:

Code: Select all

conda create --name NewPy39 python=3.9

Activate new Environment
Ask Anaconda to switch to the new environment by running the command:

Code: Select all

conda activate NewPy39

Install Numpy
Now install the latest Numpy library by typing the following command:

Code: Select all

pip install numpy

Point EViews to the new Python folder
Run EViews 12, then go to Options menu/General Options/External program interface. In the bottom "Python Home Path" field, select the new folder that was created by the new conda environment above. This usually looks like:

Code: Select all

C:\Users\<username>\Anaconda3\envs\NewPy39
Click OK to save the new path.

Try Numpy Import Again
At this point, try opening EViews connection to Python and see if you can import numpy successfully.

tinadl
Posts: 3
Joined: Tue Nov 30, 2021 12:17 pm

Re: Python Integration problem - Eviews 11 Enterprise Edition

Postby tinadl » Wed Dec 01, 2021 4:19 pm

Worked! Thank you very much!

uyanikcaner
Posts: 12
Joined: Sat Dec 05, 2020 8:31 am

Re: Python Integration problem - Eviews 11 Enterprise Edition

Postby uyanikcaner » Mon Feb 14, 2022 7:01 am

Thank you for your help. It helped integrate Python to the Eviews. However, whenever I open Eviews and try to xopen(p) and e.g. import pandas as pd or numpy as np command, it returns the same problem. I have to re-run Anaconda Prompt and re-type the codes you offered in order for Python integration in Eviews to be used properly. Do you have any suggestion for preventing this issue?

EViews Steve
EViews Developer
Posts: 788
Joined: Tue Sep 16, 2008 3:00 pm
Location: Irvine, CA

Re: Python Integration problem - Eviews 11 Enterprise Edition

Postby EViews Steve » Mon Feb 14, 2022 12:01 pm

I think I know what's going on here.

EViews is designed to work with generic Python installations, but it will also work with Anaconda environments as long as you take care of some environment related settings manually since EViews doesn't do anything specific for Anaconda.

First, you'll have to find out what your PATH setting is when running under your Anaconda Prompt:

1. Run Anaconda Prompt and switch to your preferred Python environment. Once there, run the SET PATH command to display the current PATH string. Here's what it looks in mine (I'm only showing the beginning python related values of my PATH here - yours will be much longer):
conda_home.png
conda_home.png (17.97 KiB) Viewed 21162 times

You'll notice that my PATH string contains references to both py27 (my selected conda environment) and also Python39. The reason for this is because I have regular Python 3.9 installed on my system. Also notice that the Anaconda 2.7 values are in front of my 3.9 values. Here's the list of Anaconda related path strings without the semi-colons:

Code: Select all

C:\Users\steve.yoo\Anaconda3\envs\py27
C:\Users\steve.yoo\Anaconda3\envs\py27\Library\mingw-w64\bin
C:\Users\steve.yoo\Anaconda3\envs\py27\Library\usr\bin
C:\Users\steve.yoo\Anaconda3\envs\py27\Library\bin
C:\Users\steve.yoo\Anaconda3\envs\py27\Scripts
C:\Users\steve.yoo\Anaconda3\envs\py27\bin
C:\Users\steve.yoo\Anaconda3\condabin

In order to get EViews to work with your Anaconda environment correctly, you'll have to transfer the path values above to your Windows System PATH string directly. One way to do this is to use the Windows Advanced System Properties dialog (update the System PATH value, not the User one).

Once you've updated the Windows System PATH string, call XOPEN(p) again and try the import. It should work this time.
xopen.png
xopen.png (12.9 KiB) Viewed 21162 times

Steve

uyanikcaner
Posts: 12
Joined: Sat Dec 05, 2020 8:31 am

Re: Python Integration problem - Eviews 11 Enterprise Edition

Postby uyanikcaner » Tue Feb 15, 2022 3:59 am

It worked!!! Thank you so much Steve Yoo, I appreciate it..


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 17 guests