# EnvironmentError: no Hail context initialized, create one first

**URL:** <https://discuss.hail.is/t/environmenterror-no-hail-context-initialized-create-one-first/223>\
**Category:** Help \[0.1\]\
**Created:** [May 18, 2017, 6:11pm UTC](https://discuss.hail.is/t/environmenterror-no-hail-context-initialized-create-one-first/223 "2017-05-18T18:11:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kbchoi-jax](https://avatars.discourse-cdn.com/v4/letter/k/f04885/32.png) [@kbchoi-jax](https://discuss.hail.is/u/kbchoi-jax)\
**Post date:** [May 18, 2017, 6:11pm UTC](https://discuss.hail.is/t/environmenterror-no-hail-context-initialized-create-one-first/223/1 "2017-05-18T18:11:02Z")

</div>

Trying to run Hail locally, and followed the instruction in “Get Started” documentation at [https://hail.is/hail/getting\_started.html](https://hail.is/hail/getting_started.html). Unfortunately I got the following EnvironmentError. Any comment would be greatly appreciated.

from hail import \*  
hc = HailContext()

## Using Spark’s default log4j profile: org/apache/spark/log4j-defaults.properties Setting default log level to “WARN”. To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel).

EnvironmentError Traceback (most recent call last)  
 in ()  
----\> 1 hc = HailContext()

in **init** (self, sc, app\_name, master, local, log, quiet, append, parquet\_compression, min\_block\_size, branching\_factor, tmp\_dir)

/Users/kbchoi/Projects/hail/python/hail/java.pyc in handle\_py4j(func, \*args, \*\*kwargs)  
110 raise FatalError(’%s\n\nJava stack trace:\n%s\n’  
111 ‘Hail version: %s\n’  
–\> 112 ‘Error summary: %s’ % (deepest, full, Env.hc().version, deepest))  
113 except py4j.protocol.Py4JError as e:  
114 if e.args[0].startswith(‘An error occurred while calling’):

/Users/kbchoi/Projects/hail/python/hail/java.pyc in hc()  
40 def hc():  
41 if not Env.\_hc:  
—\> 42 raise EnvironmentError(‘no Hail context initialized, create one first’)  
43 return Env.\_hc  
44

EnvironmentError: no Hail context initialized, create one first

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [May 18, 2017, 6:24pm UTC](https://discuss.hail.is/t/environmenterror-no-hail-context-initialized-create-one-first/223/2 "2017-05-18T18:24:38Z")

</div>

Hah! This is a terrible error message. The real error was something else, but it was hidden when we tried to get the version out.

Will fix this ASAP and post the pull request number here so that you can track it.

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [May 18, 2017, 7:38pm UTC](https://discuss.hail.is/t/environmenterror-no-hail-context-initialized-create-one-first/223/3 "2017-05-18T19:38:04Z")

</div>

here’s the patch: [https://github.com/hail-is/hail/pull/1849](https://github.com/hail-is/hail/pull/1849)

I’ll merge it as soon as the tests pass. Sorry about this!

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [May 18, 2017, 8:12pm UTC](https://discuss.hail.is/t/environmenterror-no-hail-context-initialized-create-one-first/223/4 "2017-05-18T20:12:56Z")

</div>

The fix is live, if you pull the latest master it should work.

And by ‘work’, I mean give you a better error message that we can actually work with 🙂

---

<div class="post-metadata">

**Author:** ![kbchoi-jax](https://avatars.discourse-cdn.com/v4/letter/k/f04885/32.png) [@kbchoi-jax](https://discuss.hail.is/u/kbchoi-jax)\
**Post date:** [May 18, 2017, 8:36pm UTC](https://discuss.hail.is/t/environmenterror-no-hail-context-initialized-create-one-first/223/5 "2017-05-18T20:36:46Z")

</div>

Thanks. Now it says I have a conflict in spark versions. It is a bit weird because I have only one spark installation.

$ spark-shell  
Using Spark’s default log4j profile: org/apache/spark/log4j-defaults.properties  
Setting default log level to “WARN”.  
To adjust logging level use sc.setLogLevel(newLevel).  
17/05/18 16:24:54 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform… using builtin-java classes where applicable  
17/05/18 16:24:54 WARN SparkConf:  
SPARK\_CLASSPATH was detected (set to ‘/home/kbchoi/hail//build/libs/hail-all-spark.jar’).  
This is deprecated in Spark 1.0+.

Please instead use:

- ./spark-submit with --driver-class-path to augment the driver classpath
- spark.executor.extraClassPath to augment the executor classpath

17/05/18 16:24:54 WARN SparkConf: Setting ‘spark.executor.extraClassPath’ to ‘/home/kbchoi/hail//build/libs/hail-all-spark.jar’ as a work-around.  
17/05/18 16:24:54 WARN SparkConf: Setting ‘spark.driver.extraClassPath’ to ‘/home/kbchoi/hail//build/libs/hail-all-spark.jar’ as a work-around.  
17/05/18 16:24:55 WARN SparkContext: Use an existing SparkContext, some configuration may not take effect.  
Spark context Web UI available at [http://x.x.x.x:4040](http://x.x.x.x:4040)  
Spark context available as ‘sc’ (master = local[\*], app id = local-1495139095129).  
Spark session available as ‘spark’.  
Welcome to  
\_\_\_\_ \_\_  
/ **/** \_\_\_ **_/ /  
 \ / \_ / \_ `/ \_\_/ '/  
/_**/ .\_\_/\_,_/_/ /_/\_\ version 2.0.0  
/_/

Using Scala version 2.11.8 (OpenJDK 64-Bit Server VM, Java 1.8.0\_131)  
Type in expressions to have them evaluated.  
Type :help for more information.

scala\> :quit

Whereas in ipython,

## In [1]: from hail import \* In [2]: hc = HailContext() Using Spark’s default log4j profile: org/apache/spark/log4j-defaults.properties Setting default log level to “WARN”. To adjust logging level use sc.setLogLevel(newLevel).

Py4JJavaError Traceback (most recent call last)  
 in ()  
----\> 1 hc = HailContext()

in **init** (self, sc, app\_name, master, local, log, quiet, append, parquet\_compression, min\_block\_size, branching\_factor, tmp\_dir)

/home/kbchoi/hail/build/distributions/hail-python.zip/hail/typecheck/check.pyc in \_typecheck(f, \*args, \*\*kwargs)  
190 def \_typecheck(f, \*args, \*\*kwargs):  
191 check\_all(f, args, kwargs, checkers, is\_method=True)  
–\> 192 return f(\*args, \*\*kwargs)  
193  
194 return decorator(\_typecheck)

/home/kbchoi/hail/build/distributions/hail-python.zip/hail/context.pyc in **init** (self, sc, app\_name, master, local, log, quiet, append, parquet\_compression, min\_block\_size, branching\_factor, tmp\_dir)  
81 self.\_jhc = scala\_object(self.\_hail, ‘HailContext’).apply(  
82 jsc, app\_name, joption(master), local, log, quiet, append,  
—\> 83 parquet\_compression, min\_block\_size, branching\_factor, tmp\_dir)  
84  
85 self.\_jsc = self.\_jhc.sc()

/usr/local/spark/python/lib/py4j-0.10.1-src.zip/py4j/java\_gateway.py in **call** (self, \*args)  
931 answer = self.gateway\_client.send\_command(command)  
932 return\_value = get\_return\_value(  
–\> 933 answer, self.gateway\_client, self.target\_id, [self.name](http://self.name))  
934  
935 for temp\_arg in temp\_args:

/usr/local/spark/python/lib/py4j-0.10.1-src.zip/py4j/protocol.py in get\_return\_value(answer, gateway\_client, target\_id, name)  
310 raise Py4JJavaError(  
311 “An error occurred while calling {0}{1}{2}.\n”.  
–\> 312 format(target\_id, “.”, name), value)  
313 else:  
314 raise Py4JError(

Py4JJavaError: An error occurred while calling o0.apply.  
: java.lang.IllegalArgumentException: requirement failed: This Hail JAR was compiled for Spark 2.0.2,  
but the version of Spark available at runtime is 2.0.0.  
at scala.Predef$.require(Predef.scala:224)  
at is.hail.HailContext$.configureAndCreateSparkContext(HailContext.scala:33)  
at is.hail.HailContext$.apply(HailContext.scala:163)  
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)  
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)  
at java.lang.reflect.Method.invoke(Method.java:498)  
at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:237)  
at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)  
at py4j.Gateway.invoke(Gateway.java:280)  
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:128)  
at py4j.commands.CallCommand.execute(CallCommand.java:79)  
at py4j.GatewayConnection.run(GatewayConnection.java:211)  
at java.lang.Thread.run(Thread.java:748)

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [May 18, 2017, 9:44pm UTC](https://discuss.hail.is/t/environmenterror-no-hail-context-initialized-create-one-first/223/6 "2017-05-18T21:44:28Z")

</div>

We’ve instituted a check at HailContext creation to make sure that the version of Spark that Hail was compiled for matches the version it’s running against – in most cases it would be okay to have minor version differences (2.0.2 vs 2.0.0) but we’ve had issues before.

I assume that you compiled this yourself with `./gradlew shadowJar`, right? You can add a Spark version like so:

```auto
./gradlew -Dspark.version=2.0.0 shadowJar

```

---

<div class="post-metadata">

**Author:** ![kbchoi-jax](https://avatars.discourse-cdn.com/v4/letter/k/f04885/32.png) [@kbchoi-jax](https://discuss.hail.is/u/kbchoi-jax)\
**Post date:** [May 18, 2017, 10:28pm UTC](https://discuss.hail.is/t/environmenterror-no-hail-context-initialized-create-one-first/223/7 "2017-05-18T22:28:48Z")

</div>

Works great now. Thank you for your help.

---

<div class="post-metadata">

**Author:** ![tpoterba](https://yyz2.discourse-cdn.com/flex036/user_avatar/discuss.hail.is/tpoterba/32/61_2.png) [@tpoterba](https://discuss.hail.is/u/tpoterba)\
**Post date:** [May 18, 2017, 10:43pm UTC](https://discuss.hail.is/t/environmenterror-no-hail-context-initialized-create-one-first/223/8 "2017-05-18T22:43:10Z")

</div>

Sure, and sorry about that first error!
