Python 3.6 tries to initialize with Python 2.7

3823
24
Jump to solution
04-03-2019 12:17 PM
MarkBinder
Frequent Contributor

I am having some major Python issues. When I try to start PyCharm using the ArcGIS Pro Python environment it tries to initialize using the Python 2.7 ArcGIS 10.6 installation. Somehow my Python installations got crossed up.

I've tried uninstalling ArcGIS Pro and reinstalling it but that has no effect.

Is there any way to solve this?

0 Kudos
1 Solution

Accepted Solutions
MarkBinder
Frequent Contributor

So I think I found the solution. In Spyder I went to 'Tools/Current user environment variables...' and cleared out the values in PYTHONPATH. That has stopped adding all of those unrelated paths and only loads the paths for each installation of Python.

View solution in original post

0 Kudos
24 Replies
curtvprice
MVP Esteemed Contributor

Be sure you have set up pycharm to use the ArcGIS Pro install. ArcGIS Pro uses Conda, so you can link it directly to its Conda environment.

This doesn't happen automatically, you need to configure it which Python exe to use.

Can ArcGIS Pro integrate with JetBrains Pycharm

0 Kudos
MarkBinder
Frequent Contributor

Right, it is using the ArcGIS Pro installation; that’s where I think the problem is because cloned environments also have the same problem. And when I try to install Spyder to a cloned environment it uses Python 2.7 packages instead of 3.6.

0 Kudos
LukeWebb
Frequent Contributor

The short and dirty answer is, inside Pycharm / Spyder / any python IDE, there is a setting "Project Interpreter", which is pointing to a python.exe in a folder such as C:\python27\python.exe

You need to update this setting to point to a place such as:

C:\Program Files\ArcGIS\Pro\bin\Python\python.exe

0 Kudos
MarkBinder
Frequent Contributor

I did set the interpreter to point to the ArcGIS Pro Python environment. I think when it tries to initialize it is using the Python.exe that is in the Python27 ArcGIS 10.6.1 folder. This seems to be a deeper Python issue than the IDE settings.

0 Kudos
curtvprice
MVP Esteemed Contributor

When you installed PyCharm or Anaconda, did you check any boxes to set .py files to launch in that environment or other checkboxes that modify your Windows default paths?  It is important to not do that because of the PATH and PYTHONPATH are messed with, pythons will not work right.

I just tried doing this last night and it worked fine in PyCharm. I configured both the 10.6/2.7 environment (which was discovered by the installer through the registry automatically) and the Pro anaconda environment in the bin/Python install folder and I could toggle back and forth between environments restart the console and successfully import the correct arcpy in each.

0 Kudos
MarkBinder
Frequent Contributor

I’ve been using the portable version of PyCharm and then pointing it to the Python environment that is installed on whichever computer I’m using.

I was able to install Spyder in a Python 3.6 environment and later I also installed it in a Python 2.7 environment. They were both successful and then I started getting the errors.

0 Kudos
DylanHarwell
Frequent Contributor

I have tried this with PyScripter, which by default has always pointed to the 2.7 python installation on any machine with ArcGIS I have ever had. And changing its Python path to the 3 installed buried way down in the Pro folder never has worked. It always resorts back to 2.7. My workaround, I write 2.7 code in PyScripter and use Spyder for 3 code. My cynical thought is it has something to do with ESRI having their hands all over everything in the python installations lol

curtvprice
MVP Esteemed Contributor

I think it has more to do with Windows being really weak with the ability to control a users application environment without risking conflict with environments needed for other applications. In Unix these kind of configurations are kind of isolated to the application you are running.

0 Kudos
MarkBinder
Frequent Contributor

I think python is messed up on the entire computer now. Any ideas on how to completely remove Python?

I'll start by completely removing ArcGIS products.

0 Kudos