0

Two approaches to setup Pyspark in an IDE are :

  1. Using Pip i.e pip install pyspark , As mentioned in the following link ( E0401:Unable to import 'pyspark in VSCode in Windows 10)

  2. By appending PySpark modules in "PYTHONPATH" path, as mentioned in following articles.

The second approach is backward compatible and can be setup in most IDEs, So wanted to know how can one setup up "PYTHONPATH" in visual studio code .

I believe something needs to be done either in settings.json , launch.json or may be even in .env file. But I could not find something concrete.

Also, I went through the visual studio code at link https://code.visualstudio.com/docs/python/environments#_use-of-the-pythonpath-variable . However was still not able to figure out

How to "append" python or PySpark modules to PYTHONPATH

Gama11
  • 31,714
  • 9
  • 78
  • 100
sumit kumar
  • 150
  • 1
  • 2
  • 13
  • I have no idea what do you mean with **PYTHONPATH** but if you have installed Python correctly (with environment variables) and installed pyspark correct (`pip install pyspark` or `pip3 install pyspark`). You should simply call: `python file.py` or `python3 file.py`. – Spirit Mar 11 '19 at 14:24
  • @Spirit , Using pip install pyspark is one way to do it, however adding pyspark.zip and py4j-0.10.4-src.zip to "PYTHONPATH" is more flexible as that same build can be used for coding in other languages and even in case of update its across all the setups. – sumit kumar Mar 11 '19 at 14:34
  • I have no experience with this option. But maybe try and make a own Environment Variable for the file. – Spirit Mar 11 '19 at 14:41
  • I'd recommend checking out [this post](https://stackoverflow.com/questions/43983718/set-global-path-environment-variable-in-vs-code) for setting environment variables for VSCode – Spencer Pollock Mar 11 '19 at 15:00

1 Answers1

1

If you want to do it via a .env file then it should be:

PYTHONPATH=/path/to/zip
Brett Cannon
  • 14,438
  • 3
  • 45
  • 40