Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Virtual Environment

#1
Hello, is it possible to set the python environment to Virtual environment in the RoboDK?
#2
RoboDK automatically includes the RoboDK/Python folder as the python path (PYTHONPATH variable) when you launch a Python program from RoboDK. You can place any dependencies there.

If you want to create different environments it may be better to setup a separate projects (for example, using VSCode or PyCharm) and install the RoboDK API for Python on your preferred Python version:
https://pypi.org/project/robodk/
The RoboDK API also works when you launch it externally (not using RoboDK).
#3
(04-25-2019, 10:38 AM)Albert Wrote: RoboDK automatically includes the RoboDK/Python folder as the python path (PYTHONPATH variable) when you launch a Python program from RoboDK. You can place any dependencies there.

If you want to create different environments it may be better to setup a separate projects (for example, using VSCode or PyCharm) and install the RoboDK API for Python on your preferred Python version:
https://pypi.org/project/robodk/
The RoboDK API also works when you launch it externally (not using RoboDK).

Hello, thanks for your sharing. I’m new to using RoboDK, and I have a question about using python with RoboDK. I have built a python virtual environment in another folder, and I have installed RoboDK library by pip in my virtual environment. However, when I want to import 3rd part library included in my virtual environment through the python program created in RoboDK software, I got a mistake "Fail to import "File "C:/Users/Appdata/Temp/Prog1.py, no module 'desired library name'". So, I want to know how to manage the python environment of RoboDK software, or how to import 3rd part library.
#4
(01-30-2024, 12:24 PM)Zhang Guoquan Wrote:
(04-25-2019, 10:38 AM)Albert Wrote: RoboDK automatically includes the RoboDK/Python folder as the python path (PYTHONPATH variable) when you launch a Python program from RoboDK. You can place any dependencies there.

If you want to create different environments it may be better to setup a separate projects (for example, using VSCode or PyCharm) and install the RoboDK API for Python on your preferred Python version:
https://pypi.org/project/robodk/
The RoboDK API also works when you launch it externally (not using RoboDK).

Hello, thanks for your sharing. I’m new to using RoboDK, and I have a question about using python with RoboDK. I have built a python virtual environment in another folder, and I have installed RoboDK library by pip in my virtual environment. However, when I want to import 3rd part library included in my virtual environment through the python program created in RoboDK software, I got a mistake "Fail to import "File "C:/Users/Appdata/Temp/Prog1.py, no module 'desired library name'". So, I want to know how to manage the python environment of RoboDK software, or how to import 3rd part library.

Hello, Albert. 

I tested some different codes and libraries, and I found that RoboDK seemed to use the Anaconda base environment. So, if I want to use some new library, do I have to install it in the base environment? 

Besides, for example, when we use python in pycharm, we may create some .py files and import them in another file, which are all placed in the same folder. I don't know how to achieve this behavior, so I tried to add some files in folder of 'Macros', naturally, I failed to import these files in a python program created in RoboDK software. Can I only define this code as a function and add it to the python program created in RoboDK? 

I don't know if I‘m right, hope for your reply.

Regards,
Guoquan Zhang
#5
(01-30-2024, 02:05 PM)Zhang Guoquan Wrote:
(01-30-2024, 12:24 PM)Zhang Guoquan Wrote:
(04-25-2019, 10:38 AM)Albert Wrote: RoboDK automatically includes the RoboDK/Python folder as the python path (PYTHONPATH variable) when you launch a Python program from RoboDK. You can place any dependencies there.

If you want to create different environments it may be better to setup a separate projects (for example, using VSCode or PyCharm) and install the RoboDK API for Python on your preferred Python version:
https://pypi.org/project/robodk/
The RoboDK API also works when you launch it externally (not using RoboDK).

Hello, thanks for your sharing. I’m new to using RoboDK, and I have a question about using python with RoboDK. I have built a python virtual environment in another folder, and I have installed RoboDK library by pip in my virtual environment. However, when I want to import 3rd part library included in my virtual environment through the python program created in RoboDK software, I got a mistake "Fail to import "File "C:/Users/Appdata/Temp/Prog1.py, no module 'desired library name'". So, I want to know how to manage the python environment of RoboDK software, or how to import 3rd part library.

Hello, Albert. 

I tested some different codes and libraries, and I found that RoboDK seemed to use the Anaconda base environment. So, if I want to use some new library, do I have to install it in the base environment? 

Besides, for example, when we use python in pycharm, we may create some .py files and import them in another file, which are all placed in the same folder. I don't know how to achieve this behavior, so I tried to add some files in folder of 'Macros', naturally, I failed to import these files in a python program created in RoboDK software. Can I only define this code as a function and add it to the python program created in RoboDK? 

I don't know if I‘m right, hope for your reply.

Regards,
Guoquan Zhang

Hello, Albert. 

Please ignore these previous messages, I made some mistakes. 

Now I know that I can add my own Python module into the folder of 'RoboDK/python'. So in conclusion, I have three questions, could you help me?

1. If I want to pip install a 3rd library, which environment I should operate?
2. If I used the Python interpreter installed for my virtual environment, if it influence the Python environment RoboDK software used?
3. I also installed robodk library in my virtual environment, I can import it in a .py file in my virtual environment, but I don't know if this import can link with RoboDK software.

Regards.

Thanks,
Guoquan Zhang
#6
You can easily install Python packages by following these steps:
  1. Select Tools-Run script
  2. Select Install Python Package
  3. Enter the name of the package.
Alternatively, you can use the command line:
  1. Open a new console
  2. Type:
    cd C:/RoboDK/Python-Embedded
  3. Install packages using Python and the pip module:
    python -m pip install your-package
Another option is to open a new console at the Python-Embedded directory by running this BAT file: C:/RoboDK/Python-Set-Path-CMD.bat

You can use your own custom Python version and environment as well and the RoboDK API will still work.
#7
(01-31-2024, 12:46 PM)Albert Wrote: You can easily install Python packages by following these steps:
  1. Select Tools-Run script
  2. Select Install Python Package
  3. Enter the name of the package.
Alternatively, you can use the command line:
  1. Open a new console
  2. Type:
    cd C:/RoboDK/Python-Embedded
  3. Install packages using Python and the pip module:
    python -m pip install your-package
Another option is to open a new console at the Python-Embedded directory by running this BAT file: C:/RoboDK/Python-Set-Path-CMD.bat

You can use your own custom Python version and environment as well and the RoboDK API will still work.
Hello, Albert.

Thanks for your help!

I don't know if I understand correctly. No matter which Python interpreter I use (embedded or my created environment), I can always call the Python libraries installed under the folders RoboDK/python and RoboDK/python_embeded, so if I want to install a package just for RoboDK, Just install it to the path RoboDK/python or RoboDK/python_embeded.

Regards
Guoquan ZHANG
#8
When you run scripts from RoboDK software, RoboDK will use RoboDK/Python as the PYTHONPATH. If you call Python scripts from your own version of Python you'll use the default settings for that version of Python.
#9
(02-01-2024, 08:46 AM)Albert Wrote: When you run scripts from RoboDK software, RoboDK will use RoboDK/Python as the PYTHONPATH. If you call Python scripts from your own version of Python you'll use the default settings for that version of Python.

Ok.

Thanks for your help!
  




Users browsing this thread:
1 Guest(s)