anaconda python 3.6.5 install - import csv fail

Started by tedventures, August 26, 2018, 08:39:53 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

tedventures

Anaconda distribution python 3.6.5 install on Mac OS X High Sierra;  Keyshot doesn't seem to recognize for scripting.
'Use local Python paths (version 3.6 only)' box is checked in Advanced preferences.
install path for Python is /anaconda3/bin
Import csv module fails in Keyshot console, but works fine in terminal.
Any one else experience and solve this? Thanks.

Morten Kristensen

Hi Ted,

This is because it is not supported to detect that due to its name and placement. What the detection functionality does is to run through PATH and known folders, trying to detect Python executables. I'm not familiar with this distribution but does it come with a "python" executable or is it named something different? Have you added "/anaconda3/bin" to your PATH?

tedventures

#2
Hi  Morten,

Anaconda is one of the most popular Python distributions available now because of the boom in data science. 

See https://en.wikipedia.org/wiki/Anaconda_(Python_distribution) 
note: make sure you copy this URL and include the closing parenthesis and paste into your browser, otherwise clicking on the link will not take you to the correct page in Wikipedia.

Since my first post, I reinstalled Python to my home directory (instead of /anaconda3/bin) and tried again from KeyShot console without success.  However, I know that Python 3.6.5 is installed and working correctly - see session below from terminal (extraneous lines removed):

Teds-iMac-Pro:~ ted$ printenv
PATH=/Users/ted/anaconda3/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
PWD=/Users/ted
HOME=/Users/ted
Teds-iMac-Pro:~ ted$ python
Python 3.6.5 |Anaconda, Inc.| (default, Apr 26 2018, 08:42:37)
[GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import csv
>>>

After exiting Python, back in terminal to show you my home .bash_profile :

Teds-iMac-Pro:~ ted$ cat .bash_profile
# added by Anaconda3 5.2.0 installer
export PATH="/Users/ted/anaconda3/bin:$PATH


Hope this helps.


Morten Kristensen

Hi Ted,

I just installed Anaconda 5.2 with Python 3.6.5, added it to my PATH and it was found just fine by KeyShot:
>>> import csv
>>> csv
<module 'csv' from '/Users/MYUSERNAME/anaconda3/lib/python3.6/csv.py'>


I see that you added it to your PATH as well but KeyShot will only use that if the terminal it's running from has it - so if you run KeyShot via the .app then it won't find it before its environment is updated. One way to do this is rebooting your machine.

tedventures

Hi Morten,

Fantastic - thank you. 

Working for me too, but not in all cases (rebooting didn't help). For what it's worth for others, here are some test results:

Mac OS X High Sierra - macOS 10.13.6 (17G65)

Success opening from Terminal:
Teds-iMac-Pro:Applications ted$ open KeyShot7.app
Success from double-click in Finder:
/Applications/KeyShot7.app/Contents/MacOS/keyshot

Fails from double-click in Finder:
/Applications/KeyShot7.app

Fails from double-click on KeyShot7 icon in LaunchPad

Also note that I'm using a Floating license
Feature:keyshot_enterprise


Morten Kristensen

You're welcome. It's still about the PATH not being set correctly for your system. When running from terminal it is. The other ways don't because of misconfiguration. You should try printing the environment variables inside KeyShot scripting. Then you can see when it's setup correctly.

tedventures

Hi Morten,

Agree and have tried numerous methods via postings all over the web to set the PATH variable system wide, not just for my terminal session.

There is a recommended method to add a file in the /etc/paths.d directory that is picked up by Apple's path_helper, which appends the paths in /etc/path which are:
/usr/local/bin
/usr/bin
/bin
/usr/sbin
/sbin

I used this method to add /Users/ted/anaconda3/bin and rebooted, launched KeyShot.app normally and ran os.environ from KeyShot console which returns (other info omitted)  'PATH': '/usr/bin:/bin:/usr/sbin:/sbin' , so KeyShot still not picking it up.

Curious if you set your PATH on a Windows or Mac, or if others using Mac OS High Sierra have solved this problem?

I'm able to do my work now, but it would be great to have the best practice solution for the KeyShot community.

Morten Kristensen

Hi Ted,

Yes, that should work but I would like to point out that KeyShot just uses the environment it is passed by the OS.

You could also double-check the manual for the shell you are using and make sure you've added your folder in the correct RC file.

As a workaround, you could place as symlink in one of the folders you know are passed to KeyShot, like '/usr/bin:/bin:/usr/sbin:/sbin', as you pointed out. That should work.

Note that on *nix, it will, in addition to PATH, also search these folders:
/usr/local/bin
/usr/bin
/bin
/sbin
/usr/sbin
/opt/local/bin
/opt/local/sbin
/usr/local/Cellar


For:
python
python3
python3.6
python36
python-3.6
python-36