Using external python environment

How do use my own python environment? I’ve added the following to my python 64-bit Module path in preferences: C:/Users/user/anaconda3/envs/touch/Lib/site-packages

When I import torch, it is recognised, but it has no attributes. I’ve tried the following in the textport:

import torch (no complaints)
print(torch.version) (AttributeError: module ‘torch’ has no attribute ‘version’)

How do I get Touchdesigner to recognise the package?

torch.__version__ ?

Yes, the editor made it boldface.

I’ve also tried the following code in an execute dat:

import sys
import os
import platform
 
def onStart():
	user = 'name' # Update accordingly
 
	condaEnv = 'touch' # Update accordingly
 
	if sys.version_info.major >= 3 and sys.version_info.minor >= 8:
		"""
		Double check all the following paths, it could be that your anaconda 'envs' folder is not in your User folder depending on your conda install settings and conda version.
		"""
		os.add_dll_directory('C:/Users/'+user+'/anaconda3/envs/'+condaEnv+'/DLLs')
		os.add_dll_directory('C:/Users/'+user+'/anaconda3/envs/'+condaEnv+'/Library/bin')
	else:
		"""
		Double check all the following paths, it could be that your anaconda 'envs' folder is not in your User folder depending on your conda install settings and conda version.
		"""
		# Not the most elegant solution, but we need to control load order
		os.environ['PATH'] = 'C:/Users/'+user+'/anaconda3/envs/'+condaEnv+'/DLLs' + os.pathsep + os.environ['PATH']
		os.environ['PATH'] = 'C:/Users/'+user+'/anaconda3/envs/'+condaEnv+'/Library/bin' + os.pathsep + os.environ['PATH']

	sys.path = ['C:/Users/'+user+'/anaconda3/envs/'+condaEnv+'/Lib/site-packages'] + sys.path

	return

In this case I’m getting a different error:
OSError: [WinError 126] The specified module could not be found. Error loading “C:/Users/name/anaconda3/envs/touch/Lib/site-packages\torch\lib\caffe2_nvrtc.dll” or one of its dependencies

Did you update the variables at the top ?

In your first post you write:

C:/Users/user/anaconda3/envs/touch/Lib/site-packages

where user would be = user

and in the second you have :

user = 'name' # Update accordingly

Spot also the encoding issues in the code:

>

should be replaced by >.

Best,
Michel

Yes I changed them. And gt is > in code