Name 'sim' is not defined

Report crashes, strange behaviour, or apparent bugs
Post Reply
polender
Posts: 5
Joined: 01 Feb 2022, 03:38

Name 'sim' is not defined

Post by polender »

Hey everyone,

I'm trying to follow a tutorial from a professor at my university and am running into issues getting the environment correctly set up and connecting to the remote API. I am trying to get the simpleTest.py file to run on my machines and It provides me with the following error message. This seems like an issue with the python import, but I'm not sure. I am also trying to use the pioneer robot within the sim and also have a threaded child script set up on a primitive shape cube that includes the

Code: Select all

 simRemoteApi.start(19999) 
to start the server and the simulation is running at the time the python env was tested. I have also disabled the default script on the robot so I can run my own custom code.

Code: Select all

Traceback (most recent call last):
  File "/Users/pjolender/Github/copeliaSimTutorial2.0/simpleTest.py", line 26, in <module>
    sim.simxFinish(-1) # just in case, close all opened connections
NameError: name 'sim' is not defined

----------------------------------------------------
The remoteApi library could not be loaded. Make sure
it is located in the same folder as "sim.py", or
appropriately adjust the file "sim.py"
----------------------------------------------------

--------------------------------------------------------------
"sim.py" could not be imported. This means very probably that
either "sim.py" or the remoteApi library could not be found.
Make sure both are in the same folder as this file,
or appropriately adjust the file "sim.py"
--------------------------------------------------------------

Program started
I believe that I have the environment set up correctly with the following files placed into the current working directory of my project.

complexCommandTest.py
depth_image_encoding.py
main.py
pathPlanningTest.py
pController.py
ply.py
readMe.txt
remoteApi.dylib
sendMovementSequence-mov.py
sendMovementSequence-pts.py
sendSimultan2MovementSequences-mov.py
sim.py
simConst.py
simpleSynchronousTest.py
simpleTest.py
synchronousImageTransmission.py
visualization.py


For reference, I'm running python 3.9 using the PyCharm IDE as well as CopelliaSim Edu version 4.3.0 on my personal machines (M1 Mac Mini, and M1 pro MacBook Pro).

Thanks so much for the help!

coppelia
Site Admin
Posts: 10375
Joined: 14 Dec 2012, 00:25

Re: Name 'sim' is not defined

Post by coppelia »

Hello,

I highly recommend you to use the ZeroMQ remote API instead: you will not struggle with installation, and will be able to use the exact same functions in the exact same way as from a CoppeliaSim script.

Your problem is linked to the fact that python doesn't find the remoteApi.dylib library. It could be a permission problem, or maybe you will have to adjust the sys.path

Cheers

Post Reply