1

I am using VS 2017 and I have installed pythonnet. I created a VS project "Python Application". I have other code (C# .NET) I would like to access from this new Python application.

I should be able to: import clr

However, in VS 2017 all works fine. I know for certain it works as not only is the CLR being imported, but I am running the .Net code (can see console outputs). The issue I am having is when I do not run in VS 2017. The purpose of this Python application is to provide demonstration to Python coding colleagues as to how to run the .Net DLLs. Said coders do NOT have Visual Studio, so the "VS Environment" magic that is happening must be done manually (when they install the .Net libs).

If I run directly from cmd or use something else (like notepadd++) I get the ModuleNotFoundError: No module named 'clr'

Where is VS hiding the clr.pyd and Python.Runtime.dll? As I understand it, these files need to be in the run directory but I am not seeing them there. As noted all works fine in VS though so it seems VS is loading those modules for me from somewhere.

denfromufa
  • 5,610
  • 13
  • 81
  • 138
N_tro_P
  • 673
  • 5
  • 15
  • 1
    What happens when you `print(clr)`? What does `sys.path` look like? Are you sure it's CPython and not, say, IronPython? – AKX Jun 07 '18 at 05:19
  • how did you install pythonnet? after `import clr`, you can check its location under `clr.__file__`. ``` >>> import clr >>> clr.__file__ 'C:\\Python\\Python36-64\\lib\\site-packages\\clr.pyd' ``` – denfromufa Jun 07 '18 at 05:21
  • @AKX if I print(clr) I get "NameError: name 'clr' is not defined" – N_tro_P Jun 07 '18 at 13:48
  • @denfromufa I am not sure how that would work since "import clr" fails and returns ModuleNotFoundError. The application exists so there is no way to get to a line "after" I import clr. – N_tro_P Jun 07 '18 at 13:51
  • I couldn't remember how I "installed" pythonnet so I dug in my system. No installer but I have the entire pythonnet solution with another system. Perhaps no install, but it is literally just those 2 files (clr.pyd and Python.Runtime.dll). However, my question stands. How is VS doing this? The files do not exist in the run directory. No this is NOT IronPython. That is a specifc different project one must use. This is a standard Python Application. NOT Python built in .Net. – N_tro_P Jun 07 '18 at 13:53
  • 1
    @N_tro_P have a look at this for pythonnet installation instructions: https://stackoverflow.com/questions/14633695/how-to-install-python-for-net-on-windows – denfromufa Jun 07 '18 at 19:08
  • Thank you @denfromufa but this still doesn't help to know what is VS doing? Without knowing, it seems that VS for a Python IDE is useless. – N_tro_P Jun 08 '18 at 13:55
  • Without complete reproducible example we can't tell much – denfromufa Jun 08 '18 at 15:09
  • @denfromufa not hard to reproduce, just create a new Python Application (in VS 2017) do an import CLR and then run from VS. See that it works. Then run from cmd. See that it doesn't work. The "code" is literally one line "import clr" which is in the OP. – N_tro_P Jun 08 '18 at 15:19
  • @N_tro_P can you check clr.__file__ and share your VS solution? – denfromufa Jun 08 '18 at 15:33
  • The path is C:\Users\\AppData\Local\Programs\Python\Python35-32\lib\site-packages\clr.pyd I am unable to share the solution due to company blocks on fileshare sites. So this answers WHERE it is, but it still doesn't make sense. VS must be strapping that location in the path somewhere and I want to be able to do that manually (without VS) – N_tro_P Jun 08 '18 at 17:16
  • you are probably launching 2 different python installations in VS and outside of it. This location for clr.pyd is default and should be located during import with no manual path registration. – denfromufa Jun 11 '18 at 10:47
  • @denfromufa yes I know that. Thus my question. I want to know what VS is doing in the creation of the environment. Clearly something extra is done in the VS environment, but I do not understand what it is. – N_tro_P Jun 12 '18 at 17:32

0 Answers0