Anaconda and Spyder won't open if PythonPath is set - python

I'm new to using Anaconda and Spyder and this must be a simple setting issue, but it's really frustrating. I need to have a PythonPath environment set because I frequently run scripts in ArcGIS which won't work without a path. However, neither Anaconda Navigator nor Spyder will not open if there is a PythonPath set. I get the splash screen, but that's it, it doesn't open. If I remove the PythonPath and reboot, Anaconda and Spyder work, but not ArcGIS. This is not an ArcGIS problem, rather Anaconda and Spyder just don't seem to like there being a PythonPath at all. Anyone have experience with this?
For reference, my PythonPath contains:
C:\Python27;
C:\Python27\Lib;
C:\Python27\Lib\site-packages;
C:\Python27\DLLs;
C:\Python27\Lib\lib-tk;
C:\Python27\scripts;
C:\Python27\ArcGIS10.3\Lib;
C:\Python27\ArcGIS10.3\Lib\lib-tk;
C:\Python27\ArcGIS10.3\Lib\site-packages;
C:\Program Files (x86)\ArcGIS\Desktop10.3\arcpy;
C:\Program Files (x86)\ArcGIS\Desktop10.3\bin
I can remove everything except the bottom five and ArcGIS scripts still work, but it doesn't fix the problem with Spyder. It probably has something to do with the files not actually being executables, but links to scripts. For example, the shortcut for Spyder points to:
C:\ProgramData\Anaconda2\pythonw.exe C:\ProgramData\Anaconda2\cwp.py
C:\ProgramData\Anaconda2 "C:/ProgramData/Anaconda2/pythonw.exe"
"C:/ProgramData/Anaconda2/Scripts/spyder-script.py"
which seems to leave a lot of room for trouble. Interestingly, if I run from the Command Prompt, the first time there are no errors but nothing happens, and the second time it displays:
Spyder is already running. If you want to open a new instance, please
pass to it the --new-instance option

I don't know that I can directly offer a fix, but a nice workaround is spyder's PYTHONPATH manager inside the program. If you open up spyder you should be able to locate the pythonpath manager (on a mac it is under "python" tab) and manually add the necessary paths.

You seem to have relic python installation kicking around and it wasn't uninstalled prior to installing ArcMap. The correct path structure for a clean installation of ArcMap with its associated python would consist of
C:\Python27\ArcGISxx.x
and there are no other files or folders in the C:\Python27 path.
I would suggest uninstalling python completely and do a 'repair' of the arcmap distribution which will reinstall python and its dependencies correctly.
In the interim, you should move the last 3 lines (which refer to arcmap) to the top of the dependency list. That may resolve things temporarily.

Related

Python -V not working or returning any error on Windows 10

I tried to upgrade python version. It didn't work so I uninstalled python from my system. Deleted from Path and re-installed it. Ever since the reinstall
python -V
doesn't work. I have set the path manually and didn't work. Uninstalled and tried again, this time checked the tick-box that says add python to path.
No matter what I do can't seem to get the commands working.
As like the picture I get nothing. The version or anything else.
How am I to fix this problem?
Reason for the behaviour
Your system is using wrong python.exe. (not the one you installed, but one coming with Windows)
How to fix this?
It's completely ok to keep the C:/Users/<user>/AppData/Local/Microsoft/WindowsApps on you PATH, but make sure that your python installation folder (folder with python.exe) is in your PATH above the C:/Users/<user>/AppData/Local/Microsoft/WindowsApps, because the PATH is checked in order from top to bottom (or left to right).
To edit the environment variables, use Win -> type "envir" to the search -> Edit environment variables for your account -> Environment Variables... -> Select from the top list (user list) the "Path" and press "Edit...".
Notes
You can check what python.exe your command is using in Powershell with Get-Command python.
You probably want to also include the /Scripts folder of your python installation to the PATH. (there are common tools like pip.exe, and any .exe coming from a package, such as ipython.exe)
This problem happens because there is a default python.exein newer Windows 10 versions. See: Who put Python in the Windows 10 May 2019 Update?
The Process PATH is not updated if you edit the User or System PATH; you need to restart the Powershell to make the changes visible. If you use terminal of an IDE, you need to close all windows for the process once.
Delete the file c:/Users/<user>/AppData/Local/Microsoft/WindowsApps/python.exe

PyCharm not recognizing my python interpreter and PIP packages. Maybe PATH issue?

So I have been having issues with getting PyCharm to find my python3 interpreter on my Mac. I have downloaded a few packages with pip from the terminal and when I use the python shell from the terminal and import them, I get no errors.
When I check where these packages are downloaded, I get this path:
/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.>7/lib/python3.7/site-packages
So the issue is when I try to use the PyCharm IDE I don't have access to these packages. I have gone into the settings to change the interpreter and I have tried all these options, none of which show my installed packages.
![1]:https://i.imgur.com/dhTg8CV.png
I have also tried navigating to that path where it shows my packages are downloaded and selecting the python.exe (the highlighted file) I find, but get this error with PyCharm ->
![2]:https://i.imgur.com/DbW5y6I.png
![3]:https://i.imgur.com/B8H4hlA.png
I have a feeling I am selecting the wrong python.exe but I don't know where to look. I also think the problem could stem from me installing iTerm and the zshrc bash program and it changed my paths, but I don't know why python would be working from my terminal then. Just in case, this is what my Path is in my zshrc file:
export PATH=$HOME/bin:/usr/local/bin:$PATH
export PATH="$HOME/.composer/vendor/bin:$PATH"
export PATH="/usr/local/bin:/usr/local/sbin:~/bin:$PATH"
Sorry for the long post and no inline images, this is my first post. Any help would be greatly appreciated! Just trying to get this to work so I can work on a project.
Update
just thought it would be useful to know that when i type "which python3" in the terminal it returns -> /usr/local/bin/python3
The simple solution is
Open the pycharm
Go to top left most side on IDE and open FILE dropdown.
Open the project which contains PIP files.
By this procedure pycharm automatic detect the virtual environment.

Why (or why not) Add Anaconda to path?

I have found a partial answer in this question:
Adding Anaconda to Path or not
But I still don't fully understand. I have had a lot of installation issues when switching from a normal installation Python to Anaconda, requiring me to completely re-install Windows... So i want to get this right now.
What happens internally when I Add Anaconda (or python for that matter) to the PATH? I plan on working with seperate conda environments for different python versions, what could go wrong if I add Anaconda to path in the installation? And what is the difference between doing it in the installation or doing it later through the command prompt? Will it affect my ability to integrate anaconda with PyCharm?
PATH is an environment variable that is a list of locations where executable programs lie (see also the wikipedia page.
Whenever you are in your command line and try to execute some program, for example regedit, then the cmd does not magically know that you mean C:\Windows\regedit.exe. Instead, it searches all locations in your PATH for an executable named regedit and finds it in C:\Windows which is one of the standard parts of PATH in Windows.
That is also, why messing with the PATH can be dangerous if you don't know what you are doing, because it might lead to things not working anymore if, for example you delete parts of the path or add custom directories to it.
That being said, you should now have an idea what happens when you "Add anaconda to path". It simply means, that Anaconda adds the directory where its executables lie to the PATH, hence making it findable when, for example you type conda in your cmd.
That being said, adding Anaconda to PATH is something that is convenient, because the commands can always be found automatically and they will also be found by other programs scanning your PATH for a python executable.
At the same time it is not necessary. When you use e.g. pycharm, then you can specify the path to the interpreter inside of pycharm. it does not necessarily need to be present in your PATH.
Note:
I personally have it on my PATH because I am too lazy to open an Anaconda prompt each time I need it in a cmd and I do not see the harm in it if you understand the consequences and its my only python installation anyway.
Also Helpful:
On windows, you can use the where command to find out from where commands are loaded. For example:
where regedit
gives
C:\Windows\regedit.exe
This can be especially helpful when trying to debug PATH issues
The python.exe of the base environment resides in the
C:\Users\USERNAME\AppData\Local\Anaconda3 folder
If you add this folder to the PATH, you can call that version directly from the prompt and Python will also find many of the installed packages via that anchor folder. However, this is not true for e.g. the Numpy package which heavily depends on compiled C libraries. So you would also need to add the following folders to the PATH:
C:\Users\USERNAME\AppData\Local\Anaconda3\Library\mingw-w64\bin;
C:\Users\USERNAME\AppData\Local\Anaconda3\Library\usr\bin;
C:\Users\USERNAME\AppData\Local\Anaconda3\Library\bin;
C:\Users\USERNAME\AppData\Local\Anaconda3\Scripts;
C:\Users\USERNAME\AppData\Local\Anaconda3\bin;
This is exctly what the activation is for, plus it also gives you the option to easily switch between environments.
Bottom line: Adding Anaconda to the PATH might help in simple cases, but the whole concept of Anaconda's dependency management depends on environments and their activation. It's better to use Anacona the proper way right from the beginning and NOT to add Anaconda to the PATH.

Adding Python 2.7 & 3.x Interpreters to PyCharm

I'm having issues adding a project interpreter to PyCharm from a new Anaconda environment. I have Anaconda2 installed with one Python 2.7 environment (C:\Anaconda2\python.exe) that I've been using on Pycharm without issue for several months.
I am attempting to add a second Python 3.6 interpreter (from C:\Anaconda2\envs\py36\python.exe) to my PyCharm. After adding the Local Interpreter to Pycharm, I run into a MS Visual C++ Runtime Error R6034 "An application has made an attempt to load the C runtime library incorrectly".
From cursory googling, it seems that there could be a runtime DLL conflict (potentially msvcr90.dll) between Python 2 & 3. All fixes I see involve editing the executable path of the application, but I don't think this is feasible for my Pycharm use case. How do I get rid of this error, or just generally be able to use both Python 2 & 3 interpreters through my PyCharm?
I think that's the problem with Anaconda and different msvc dll in the computer.
You can test the conda command in the command line, to see if R6034 happens. If it happens, try the following solution:
I had a similar problem with Anaconda3 and Python27. I solved this problem via executing the following command in cmd, outside of any conda environment:
conda install msvc_runtime
After installing the packages, open a new command and test if the R6034 error still appears.
I had a similar issue and was able to resolve it by selecting:
File --> Invalid Caches / Restart...
from PyCharm's main menu.
You may also want to double check that any Conda Environments that you have defined as Python Interpreters in PyCharm are properly configured per the docs
This issue was absolutely maddening. Million R6034 error windows would just keep popping up one after another if I just wanted to get help on a function. I researched it for months, on/off, opened tickets with JetBrains to no avail.
If you need to have multiple versions of Anaconda, and if you have Anaconda paths in your PATH, before launching PyCharm, delete all Anaconda paths from PATH, and then start PyCharm. You need to create a separate wrapper launcher script for PyCharm to fix PATH before PyCharm is started. Note that alternative of starting PyCharm and then fixing interpreter and python console PATHS inside PyCharm do not really work. Because PyCharm may be using a system path to access python to read documentation etc. So the only clean fix is to fix the system PATH before PyCharm starts.
Once you understand what needs to be done, then you can use your own steps/tools. This worked for me:
Create a script that modifies PATH. I used Python for that, sed or any other tools are fine too. The script simply examines each path element and removes it if it refers to Anaconda, and then puts it back together:
path_cleanup.py:
path_old = os.environ['PATH']
path_python_removed = [loc for loc in path_old.split(pathsep) if not ('python' in loc or 'Ana' in loc)]
print(pathsep.join(path_python_removed))
Create Powershell script to fix PATH and start PyCharm from that clean environment. To find PyCharm path, the simplest is to start it up the usual way, and head to Task Manager, right mouse click on pycharm64.exe process and select "open file location" to get the full path.
pycharm_clean.ps1
$Env:Path=python path_cleanup.py # call the script to fix the PATH
start-process $PYCHARM_PATH\pcharm64.exe -WindowStyle Hidden # enter your full path to pycharm and put it into background.
You can create a shortcut to launch pycharm_clean.ps1 + you can add it to your windows start up folder to be launched upon login: %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup\
If you use BASH inside Cygwin, then steps for path clean up require a bit more tuning, but nothing you cannot do. If you need help, put a comment and I can add that script as well.

Python missing module v 2.7.3 and Windows 7: Installed fuzzywuzzy, imports in powershell, not in IDLE

I'm betting there's a simple solution to this problem that I don't know, and from googling and stackoverflowing around it seems to have something to do with setting a path.
I have anaconda installed on my computer and it seems to use python 2.7.4. I also have python 2.7.3 installed, which seems to be the version being used when I open up IDLE. When I installed fuzzywuzzy using 'python setup.py install' it's installed in the anaconda folder and using python in powershell, the command 'from fuzzywuzzy import fuzz' works fine, but when doing the same thing in IDLE I get a missing module error.
Is there a way to reconcile the two versions of Python? Can I get them to share packages, or delete one of the versions without ruining everything?
I tried doing this:
'''
Setting the PYTHONPATH / PYTHONHOME variables
Right click the Computer icon in the start menu, go to properties. On the left tab, go to Advanced system settings. In the window that comes up, go to the Advanced tab, then at the bottom click Environment Variables. Click in the list of user variables and start typing Python, and repeat for System variables, just to make certain that you don't have mis-set variables for PYTHONPATH or PYTHONHOME. Next, add new variables (I did in System rather than User, although it may work for User too): PYTHONPATH, set to C:\Python27\Lib. PYTHONHOME, set to C:\Python27.
'''
then reinstalled fuzzywuzzy, and it installed in the C:Python27 folder and works in IDLE, but now Kivy doesn't work!
Do I need to reinstall that too? Or is there a Path sharing fix?
Try to wrap one of your conflict programs in CMD file. Like python-virtualenv.

Categories

Resources