Openai Gym Setup Problem Module Not Found - python

I'm trying to use Open AI's anytrading environment, but I'm running into this issue during setup. Has anyone come across this before?
ModuleNotFoundError: No module named 'gym.wrappers.order_enforcing'
import gym
import gym_anytrading
from stable_baselines3.common.vec_env import VecFrameStack, DummyVecEnv
from stable_baselines3 import A2C
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
env = gym.make('stocks-v0')

Related

Cannot import name 'Maze' from 'envs'

Running the following code in Jupyter and getting this error: cannot import name 'Maze' from 'envs'
import sys
sys.path.append(r'c:\users\mycomputer\appdata\local\packages\pythonsoftwarefoundation.python.3.10_qbz5n2kfra8p0\localcache\local-packages\python310\site-packages')
import gym
import numpy as np
from IPython import display
from matplotlib import pyplot as plt
from envs import Maze
%matplotlib inline
This worked for me:
!pip install envs (jupyter notebook code)
Take the script from GitHub page and save as envs.py in site-packages/envs folder.
from envs.envs import Maze (jupyter notebook code)

tensorflow keras import issues when loading retinanet model

%matplotlib inline
%load_ext autoreload
%autoreload 2
# external modules
from tensorflow import keras
from keras_retinanet import models
from keras_retinanet.utils.image import read_image_bgr, preprocess_image, resize_image
from keras_retinanet.utils.visualization import draw_box, draw_caption
from keras_retinanet.utils.colors import label_color
from keras_retinanet.utils.gpu import setup_gpu
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import cv2
import os
import numpy as np
import time
import csv
import math
import utm
import shapefile
import scipy
from scipy.spatial import distance
from urllib.request import urlopen
# internal modules
from utils import *
# set file path
root = os.getcwd()
rcnn_model_root = os.path.join(root, "trained_models")
input_gsv_root = os.path.join(root, "input_gsv")
output_gsv_root = os.path.join(root, "output_gsv")
output_shp_root = os.path.join(root, "output_shp")
rcnn_model_name = "resnet101_csv_25_inference.h5"
rcnn_model_path = os.path.join(rcnn_model_root,rcnn_model_name)
model = models.load_model(rcnn_model_path)
Every time I try to run this code I get issues with keras/tensorflow imports.
AttributeError: module 'keras.utils.generic_utils' has no attribute 'populate_dict_with_module_objects'
I was told to do from keras import tensorflow or something like that, but then I get other issues like not recognizing Freeze. This was run by someone else with a specific configuration, so downgrading packages has not worked.
keras_retinanet repository is deprecated to access from newer versions of Tensorflow.
However you can access this repository in tensorflow 2.3.0 and keras 2.4 by using below code.
!pip install tensorflow==2.3.0
!pip install keras==2.4
!pip install keras_retinanet
Please find this link to get more details on keras_retinanet repository.

ImportError: cannot import name 'MarianMTModel'

import numpy as np
import torch
import torchvision
from transformers import MarianTokenizer, MarianMTModel
from typing import List
I'm getting
ImportError: cannot import name 'MarianMTModel'
I've already installed transformers. What can I do to solve this issue?
Edit : Does this import Marian model implemented in C++?

ImportError: No module named deepmolecule.rdkit_utils

When I tried to python running,
I got the error that
ImportError: No module named deepmolecule.rdkit_utils
so I search about "deepmolecule.rdkit_utils" at google, but there are no exist about that module information.
How can I solve this problem?
This is importing modules in the python script file.
import csv
import subprocess
import numpy as np
import numpy.random as npr
import matplotlib.pyplot as plt
import copy
from deepmolecule.rdkit_utils import smile_to_fp
from rdkit.Chem import Descriptors
from rdkit import Chem
from rdkit.Chem import rdMolDescriptors
Apparently, the module got renamed to neuralfingerprint and is called nfp at pypi. Hence, you can install the module by running pip install nfp in your shell. Note that you might need to change the name of the module in your script.

Segmentation fault when importing libraries in Python

I am trying to import the following libraries in python:
import os, sys, random, glob, argparse, math, gc
import cv2
import dlib
import imutils
from imutils import face_utils
import matplotlib
import matplotlib.pyplot as plt
from skimage.feature import hog
from skimage import data, exposure
import sklearn
from sklearn import svm, metrics
import numpy as np
import pandas as pd
from bcolz import carray
from tqdm import tqdm
from time import sleep
import datetime as dt
All these libraries are installed in a conda environment and working when I import them in a jupyter notebook.
However, when I try to import them in the terminal or using a script, as soon as I execute:
import matplotlib.pyplot as plt
There is a:
Segmentation Fault(core dumped)
I wonder why it works in jupyter notebook but not in terminal
Because anaconda is a virual envirounment and it works on the jupyter-notebook but not in your OS command line. If you want to use it on the command line, it is recommended to install python, pip and then the packages that you need (all on your command line).
I personally recommend to install pycharm IDE to test your code locally. It is really easy to install and it tries to recognize your python installation. There you can easily add all the packages you need in configuration and import them in the code.
Here is how to add packages (e.g.numpy) in pycharm
Select your Project in Pycharm navigation side
File > Settings ( Ctrl + Alt + s )
Project
Project Interpreter
Plus button
Search for Numpy
Install Package

Categories