0

I've created a virtual environment using

conda create --name py 

And my initial plan was to add a directory to the PYTHONPATH variable but only for the py virtual environment.

I since found an alternative solution that uses .pth files. I've followed the instructions and put the file containing my package into an plain text file with a .pth extension and saved into the site-packages directory for the py environment but this does not allow my to import my package.

In summary: I put this path

`C:\Users\Ciaran\Documents\PyCoTools` 

which contains the setup.py for my package into a plain text file and saved to

C:\Anaconda2\envs\pycotools\Lib\site-packages\pycotools.pth

However I still cannot import my package from anywhere other than the package directory. Can anybody point out what I'm doing wrong?

CiaranWelsh
  • 7,014
  • 10
  • 53
  • 106
  • You can automatically set environment variables when the environment is activated. See: https://conda.io/docs/using/envs.html#windows – darthbith Jun 19 '17 at 12:49

1 Answers1

0

From the commands and paths you have described, I would say, that you put the pth file in the site-packages directory of a wrong virtual environment: in conda params you named your VE as py, but the pth file is stored in VE for pycotools.

The pth file should be available to the python interpreter with which you run your script. The interpreter scans its site-packages directory and adds the paths from the pth files to its sys.path. That is you can inspect whether your path is added by printing the contents of sys.path.

Another thing that comes to my mind is that a directory where your setup.py is located is not relevant if the module itself is located somewhere else. The pth file just allows you to patch your sys.path, not to install your package. If the package requires installation, you should better install it in your specially created VE.

newtover
  • 31,286
  • 11
  • 84
  • 89