Search code examples
pythonmodulenotfounderror

ModuleNotFoundError: No module named 'urlparse'


I am getting the following error when I am importing StockTradingEnv. I cannot understand how to do away with it.

from env.StockTradingEnv import StockTradingEnv

I even tried importing urlparse the following, but even that does not help

from urllib.parse import urlparse

Background: I am using the tutorial here to learn how to make a reinforcement learning environment from this blog.

ERRoR

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-68b0ade668b4> in <module>
      7 from stable_baselines import PPO2
      8 
----> 9 from env.StockTradingEnv import StockTradingEnv
     10 import pandas as pd

~\Anaconda3\lib\site-packages\env.py in <module>
      2 
      3 from os import environ
----> 4 from urlparse import urlparse as _urlparse
      5 
      6 

ModuleNotFoundError: No module named 'urlparse'

Solution

  • urlparse was its own built-in (i.e., NOT pip-installable) module in Python 2, and was moved to urllib.parse (also in the standard lib) in Python 3. For some reason the env package that you have installed is still referring to the old location. That needs to be updated with the new module. You can edit it directly, see if a new version is available, or request an update to its source, depending on your time and abilities.