Hello,
I have developed a Python library consists of some functions and classes and want to import it in a Python Child Script in V-REP. Could you please help me how can I import it? I have copied the .py associated file in the current directory of my V-REP file, but the module could not be imported.
Regards,
Import a custom python library
Re: Import a custom python library
Hello,
can you tell me the error message you are seeing?
Just for info, we will release a new CoppeliaSim version (V4.6) in less than 2 weeks, and Python support will be greatly improved.
Cheers
can you tell me the error message you are seeing?
Just for info, we will release a new CoppeliaSim version (V4.6) in less than 2 weeks, and Python support will be greatly improved.
Cheers
Re: Import a custom python library
Thank you so much for your response. The module I have developed is named Inteligent_Controller, and when I import it in the child script, the error message " No module named 'Inteligent_Controller' " is shown.
regards,
regards,
Re: Import a custom python library
Please show me your child script code
Re: Import a custom python library
Code: Select all
import torch
import torch.nn as nn
import numpy as np
import torch.nn.functional as F
import torch.optim as optim
import random
import torch.utils.data as data
from collections import deque as dq
import copy
import os
import Inteligent_Controller
class Environment():
def __init__(self, Xc_min, Yc_min, delta_Xc, delta_Yc, max_episod_time_stem):
self.Xc_min = Xc_min
self.Yc_min = Yc_min
self.delta_Xc = delta_Xc
self.delta_Yc = delta_Yc
self.Xc_max = self.Xc_min + self.delta_Xc
self.Yc_max = self.Yc_min + self.delta_Yc
self.delta_Phi = 2 * np.pi
self.state = [0., 0., 0., 0., 0., 0.]
self.fail = False
self.done = False
self.Zc = 0
self.alpha = 0
self.beta = 0
self.done_timestep_record = 0
This is a part of the code I have developed, and the error is associated with line 11 ("import Inteligent_Controller").
Inteligent_Controller is the name of a python module consists of some classes and functions that I have developed, and its .py file is in the directory of .ttt file.
Regards,
Re: Import a custom python library
Hello,
the scene path is not automatically added to the package search path (only the 'python' directory of CoppeliaSim is).
You can add your scene path to Python's package search path with:
the scene path is not automatically added to the package search path (only the 'python' directory of CoppeliaSim is).
You can add your scene path to Python's package search path with:
Code: Select all
import sys
scenePath = sim.getStringParam(sim.stringparam_scene_path)
sys.path.append(scenePath)
# import Intelligent_Controller
Re: Import a custom python library
It works properly.
Many thanks Ferri.
Many thanks Ferri.