2

I'm using PyCharm and running a script by clicking the "Run" button, which executes the script in the "Run" environment. Interpreter is Anaconda 3.5. The script begins with import pandas as pd. It's been always working perfectly until just now when I clicked 'Run' I got an unexpected error raised:

D:\Anaconda3\python.exe MY_PATH
Traceback (most recent call last):
  File MY_PATH, line 2, in <module>
    import pandas as pd
  File "D:\Anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
    "Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['pytz']

This error persists even after I uninstalled and reinstalled both pytz and pandas.

On the other hand, pandas has been always working properly in the IPython console environment (with the same interpreter as the "Run" environment). Such an error never occurs in the console.

What could be wrong? Please help me. Thanks!


As Julian noted, the problem is most likely due to pytz being absent from the "Run" environment, although it's present in the IPython console environment. So how can I restore pytz in the "Run" environment in PyCharm?
Vim
  • 1,436
  • 2
  • 19
  • 32
  • This is almost certainly because you don't have pytz installed in the correct environment. PyCharm will often create a virtual environment for your interpreters to run in when creating a project. The answer from @Tanvir is correct, but you need to run it in the right environment. – Julian Nov 07 '18 at 18:00
  • @Julian thanks, it seems to be the case. Could you also kindly tell me how to restore pytz in the Run virtual environment? – Vim Nov 07 '18 at 23:42
  • Usually pycharm will underline missing libraries when you put your cursor over the import. If not here is a pretty detailed explanation of how to install it: https://www.quora.com/How-do-I-include-Python-external-libraries-like-NumPy-and-Pandas-in-PyCharm – Julian Nov 11 '18 at 17:31
  • +1, but in anaconda. pandas doesn't load if python is called in the command line. But it works fine inside spyder. Environment is same. However, if kernel crashes and is restarted in spyder, then pandas doesn't load again. Issue is always related to pytz. – Raf Nov 16 '18 at 20:02
  • @Raf I solved the problem by reinstalling both conda and pycharm. But take heed of the latest pycharm version which doesn't correctly set the PATH variable for Windows, and you have to manually add several paths to PATH to ensure functionality. See https://stackoverflow.com/a/27199024 for details. – Vim Nov 17 '18 at 06:40
  • @Vim I did re-install anaconda, but no luck. I'm in Linux, path variable is set properly. I got as far as getting an old laptop, fresh install Linux Mint on it (even erase home folder), installed fresh anaconda, and *same* problem. – Raf Nov 17 '18 at 09:27

1 Answers1

1

can you try this once and check if the error remain,

pip install python-dateutil pytz --force-reinstall --upgrade
Tanvir
  • 154
  • 14