I am trying to use Linter with atom, on some python files and I keep getting this error.
Console Error Output. I am not sure what to do here, Python is on the PATH and so is flake8.
Can anyone provide clarification here?
Also I am using Python 3.7.0
Let speak a bit about your environment. Unfortunately, I can't suggest what exactly you need to do as you provided very little information. Nevertheless, your question contains enough information for a generic answer.
The flake8 tool could be in your PATH in terminal (whatever you use), but not in PATH of the Atom editor. You could achieve your goal by one of the following actions or a combination of them.
Modifying global PATH, like user PATH in Windows Environment variables, or /etc/paths in macOS (I have no information if ~/.profile would work)
Trying to run tool directly by full path (for example, /opt/local/Library/… or C:\Python37\…)
Use script-wrapper, which will set required variables and enables Virtual Environment if needed.
Related
I am using MSYS2 as my terminal in Visual Studio Code for GCC support and to use a few tools that are easier to build often in a Linux environment. However, I would like to install Python on Windows and use that instead of Python packaged with MSYS2. My current workaround is to define the following alias in my .bashrc:
alias python='$PYTHONPATH/../../python.exe'
alias pip='$PYTHONPATH/../../pip.exe'
I recently tried using venv and that is causing problems as when I type python from the MINGW terminal, it points to my Windows python instead of the venv python. This is not a bug obviously, but I need a way to use Windows python instead of MSYS2 python for packages like numpy, tox, matplotlib, etc. because the MSYS2 packages for those are a headache and currently, tox+pytest in MSYS2 does not work. At this time, my solution above works for everything I've thrown at it in Python.
So, my question is how do I use my Windows Python install instead of the POSIX/Windows MSYS2 Python without the above hack? Is there a way I can define the PATH to include my Windows Python as the first entries in MSYS2 PATH?
Here is what it looks like right now:
$echo $PATH
/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37/Scripts:/c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37
I would like to know how to make it the following instead, delete python from MSYS2, or find another way to accomplish this.
/c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37/Scripts:/c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:...
You have to put the path for /c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37 and /c/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37/Scripts before those on the msys2, right? Then I wouldn't try to use the terminal as it's too tricky, so, I will use the control panel to do it more easily. Here are some screenshots how I will do that for you.
(Sorry that I couldn't put the pictures, but the links for them instead, I couldn't put any pictures as I am a new member. Also, sorry I made the instructions too detailed.)
First, open search box with Windows+S key.
Then, choose the environment variables options from the window.
Then, choose the PATH system variable at the bottom section, and choose edit (the upper is the user PATH, and the bottom is the system PATH)
This is how it looked before:--
Then, choose C:/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37 and click “Move Up” until done. Likewise, do it same with “C:/Users/Glen.Nicholls/AppData/Local/Programs/Python/Python37/Scripts” until it's on the top.
This is how it looks now:--
After you are done, restart your terminal and hopefully, it will work. :D
I want to switch over to VS Code. I did the following to enable python with the packages I typically use, including a local utilities package on this machine:
Searched for the setting python.pythonPath and made it PycharmProjects/Project/venv/Scripts/python.exe for both this workspace and for my user
Changed my Windows user PYTHONPATH to PycharmProjects/Project/venv/Scripts/python.exe
Tried PycharmProjects/python.exe;local-utilities-directory
However, the folder I'm trying to manually set won't show up as a possible option when I click on my interpreter in the bottom right. Instead I'm defaulting to an older interpreter that doesn't have all the packages I've amassed.
While I can access some packages, while trying to pull in my personal utilities library, pip fails (the term pip is not recognized...)
I see that there are a few other ways to change the python path, however, to my understanding, whether you do it in a .json or via the IDE UI, shouldn't actually matter.
Any help would be appreciated.
So, I think I messed things up by offering too many paths.
I had to double check that the exact same path showed up first in:
Work setting pythonPath
User setting pythonPath
Windows profile path
Windows profile PYTHONPATH
I deleted the other "backup" paths, and it ended up working.
I am using Microsoft Visual Studio Code 1.30.2 on macOS Mojave 10.14.3. In the settings of VS Code, I have required it to use the external Terminal.app application on macOS. I also have an Anaconda distribution of Python installed.
Note that the PATH variable here reads:
~ » $PATH
bash: /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/anaconda3/bin:/anaconda3/condabin: No such file or directory
The order above is different from what I get if I fire up the regular Terminal app and get the PATH.
~ » $PATH
-bash: /anaconda3/bin:/anaconda3/condabin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin: No such file or directory
What this effectively does is switch the versions of Python when I type in python in the two cases. In the regular terminal, I get Python 3 right away, whereas in VS Code, I am faced with Python 2.
How do I change the PATH in VS Code so that whenever I type the words python, I am always given Python 3 instead of 2?
P.S. Please note that while editing Python code in VS Code, I can always select which interpreter I want to use, but that does not change the situation with the terminal underneath.
I had the same problem, and I have a workaround solution.
I just add one line
export PATH="/Users/username/anaconda3/bin:$PATH" into .bash_profile or .zshrc
The orifinal $PATH in vscode is
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/username/anaconda3/bin:/Users/username/anaconda3/condabin
And then my $PATH in vscode become /Users/username/anaconda3/envs/py36/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/username/anaconda3/bin:/Users/username/anaconda3/condabin
Please give it a try. I wish the workaround might help. Thanks :)
It sounds like your Workspace setting python.pythonPath is set explicitly to the /usr/bin. Set that to match your preferred $PATH and you should be good to go.
Go to Preferences in VS Code, search for python.pythonPath, switch to Workspace, and set as desired.
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.
I need to perform some custom settings for the python interpreter: specifically related to pyspark: the "interpeter" will actually be the spark-submit (aka pyspark) shell script. The intent is to be able to run pyspark jobs within the python console. Running within a Run Configuration would also be just fine: this would be an alternate approach.
I use IJ Ultimate - which has good python support: except well maybe for this particular use case.
Let us compare to pycharm - and specifically an ability to customize the interpreter - including setting local, remote, or virtualenv:
The Intellij Ultimate seems to lack those options: instead it is pointed to the libraries for a python sdk. That will not be sufficent for the given use case:
Here is the dropdown: notice there is no way to add a custom python interpreter.
So is there a way in Intellij to set the interpreter path? I want to set it to $SPARK_HOME/bin/pyspark ?
PyCharm and IntelliJ have the exact same options to add and configure Python code.
PyCharm just makes it easier.
Those windows do not have anything for interpreters
Pretty sure it does... You add interpreters here.
bin/pyspark is not an interpreter, it is a shell script. You just set the regular Python interpreter.You also need to add the Pyspark libraries. (See below)
Then, you configure the environment variables here (Run Configurations) (see those below)
As far as PySpark libraries go, you have to add these (use the full path, not variables)
$SPARK_HOME/python/
$SPARK_HOME/python/lib/py4j-X.X-src.zip
You also need to set these variables in the Edit Configurations window shown
SPARK_HOME = path to spark
PYTHONPATH = path to py4j-X.X-src.zip (also need to append the path to the current python interpreter's directory, I believe)
Ref:
How to link PyCharm with PySpark?
https://github.com/ybenoit/pyspark-ide-starter (it's got some French in it, but it's still readable)
And here's a video of some code running
https://www.youtube.com/watch?v=u-P4keLaBzc