Python module not importing after installing programmatically - python-3.8

I have attempted to follow the advise found here: https://stackoverflow.com/a/58040520/3403085
but I am still getting an error. See my code below:
import subprocess
import sys
try:
import pandas
except ImportError:
subprocess.call([sys.executable, "-m", "pip", "install", 'pandas'])
finally:
import pandas
print(pandas.__version__)
Here is the output when I run the command:
Collecting pandas
Downloading https://files.pythonhosted.org/packages/63/e0/a1b39cdcb2c391f087a1538bc8a6d62a82d0439693192aef541d7b123769/pandas-0.25.3-cp37-cp37m-manylinux1_x86_64.whl (10.4MB)
100% |████████████████████████████████| 10.4MB 13.8MB/s
Collecting python-dateutil>=2.6.1 (from pandas)
Downloading https://files.pythonhosted.org/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl (227kB)
100% |████████████████████████████████| 235kB 13.9MB/s
Collecting pytz>=2017.2 (from pandas)
Downloading https://files.pythonhosted.org/packages/e7/f9/f0b53f88060247251bf481fa6ea62cd0d25bf1b11a87888e53ce5b7c8ad2/pytz-2019.3-py2.py3-none-any.whl (509kB)
100% |████████████████████████████████| 512kB 11.7MB/s
Collecting numpy>=1.13.3 (from pandas)
Downloading https://files.pythonhosted.org/packages/9b/af/4fc72f9d38e43b092e91e5b8cb9956d25b2e3ff8c75aed95df5569e4734e/numpy-1.17.4-cp37-cp37m-manylinux1_x86_64.whl (20.0MB)
100% |████████████████████████████████| 20.0MB 14.1MB/s
Collecting six>=1.5 (from python-dateutil>=2.6.1->pandas)
Downloading https://files.pythonhosted.org/packages/65/26/32b8464df2a97e6dd1b656ed26b2c194606c16fe163c695a992b36c11cdf/six-1.13.0-py2.py3-none-any.whl
Installing collected packages: six, python-dateutil, pytz, numpy, pandas
Successfully installed numpy-1.17.4 pandas-0.25.3 python-dateutil-2.8.1 pytz-2019.3 six-1.13.0
Traceback (most recent call last):
File "test.py", line 9, in <module>
import pandas
ModuleNotFoundError: No module named 'pandas'
If I run the script a second time, the pandas module gets imported successfully, without re-installing, and I get the following output:
0.25.3
I can also uninstall by running python3 -m pip uninstall pandas so I can confirm that it is indeed installed. Any ideas why it fails if pandas isn't already installed?

The solution is in another answer in that thread:https://stackoverflow.com/a/24773951/6417038
finally:
globals()[package] = importlib.import_module(package)

Related

Why is import pandas giving me an error message?

Hi I have installed pandas into my virtual environment in VS Code. I can import other modules that came when pip installed pandas(numpy) but it gives me:
Traceback (most recent call last):
File "/Users/aidan/VS_Studios/Graphing Data/main.py", line 2, in <module>
import pandas as pd
ImportError: No module named pandas
When I try and import pandas into my main.py file. This is my virtual environment:
I have wheels installed and have python running on 3.11.8 and everything is local.
Please help thank you!
I have tried unistalling pandas and checking to see if both my interpreter pip and python are all on the same version, they are. IDK what else I need to do.

pandas installed, but shows ModuleNotFoundError When running python script

Windows 11;
Tried Anaconda, PyCharm, Python IDLE, and PowerShell;
installed pandas under PyCharm/Terminal, PowerShell:
using pip3 install pandas
In PowerShell, it works with input:
Python
import pandas
In Pycharm,
In the terminal, when I tried to install pandas again, it showed "Requirement already satisfied: pandas in d:\anaconda3\lib\site-packages (1.4.4)..."
However, it still shows "ModuleNotFoundError: No Module named 'pandas' when I run a.py with just one sentence:
import pandas
What's wrong?

Problem importing pandas after succesfull installation on mac

Although it seems that pandas is installed successfully on my mac
>sudo -H pip install --user pandas
DEPRECATION: Python 2.7 will reach the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 won't be maintained after that date. A future version of pip will drop support for Python 2.7. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
Collecting pandas
Downloading https://files.pythonhosted.org/packages/52/ff/912fe03a623a70bcf297d466013a0b4f4c68c3b60f86bf226682d061fc09/pandas-0.24.2-cp27-cp27m-macosx_10_6_intel.macosx_10_9_intel.macosx_10_9_x86_64.macosx_10_10_intel.macosx_10_10_x86_64.whl (16.7MB)
|################################| 16.7MB 1.7MB/s
Collecting python-dateutil>=2.5.0
Downloading https://files.pythonhosted.org/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl (227kB)
|################################| 235kB 1.4MB/s
Collecting numpy>=1.12.0
Downloading https://files.pythonhosted.org/packages/09/96/84cf406fe7d589f3dba9fc0f737e65985a3526c6d8c783f02d4b5a10825d/numpy-1.16.6-cp27-cp27m-macosx_10_9_x86_64.whl (13.9MB)
|################################| 13.9MB 1.7MB/s
Collecting pytz>=2011k
Downloading https://files.pythonhosted.org/packages/e7/f9/f0b53f88060247251bf481fa6ea62cd0d25bf1b11a87888e53ce5b7c8ad2/pytz-2019.3-py2.py3-none-any.whl (509kB)
|################################| 512kB 1.4MB/s
Collecting six>=1.5
Downloading https://files.pythonhosted.org/packages/65/eb/1f97cb97bfc2390a276969c6fae16075da282f5058082d4cb10c6c5c1dba/six-1.14.0-py2.py3-none-any.whl
Installing collected packages: six, python-dateutil, numpy, pytz, pandas
However, while trying to use it (python 2.7.17 )I do get an error
>>> import pandas as pd
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named pandas
>>>
any ideas ?
TIA

Pandas giving me an import error for Datautil?

I am trying to import the pandas module. However, when attempting to run my code, I get the following error:
raise ImportError('dateutil 2.5.0 is the minimum required version')
ImportError: dateutil 2.5.0 is the minimum required version
However, I already have the 2.5.0 verison on my computer, as seen from the following message when attempting to pip install.
Requirement already satisfied: python-dateutil in /Users/nat/Library/Python/3.5/lib/python/site-packages (2.5.0)
Does anyone have any suggestions on what could be the problem?
Try installing below package,
pip install python-dateutil==2.5.0

No module named 'pandastable'

I'm trying to change table wrote by me on tkinter with the pandastable one in order to do the handling of data directly from a pandas.DataFrame.
But despite I have already installed Anaconda3 with matlplotlib, numpy, pandas ect. modules when i would like to import pandastable I have trouble.
This is the problem:
import pandastable
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
import pandastable
ImportError: No module named 'pandastable'
pip install pandastable
Requires python>=3.3 or 2.7 and numpy, matplotlib and pandas.
See: pandastable on github
edit: You may have multiple Python environments installed on your machine. Anaconda uses conda install to keep things in check but pandastable doesn't seem to be available through Anaconda packages. Make sure you are installing to the same Python environment that your script uses. You might also try:
pip3 install pandastable