2 votes

Erreur de liaison de port dans PySpark

J'ai essayé de faire fonctionner PySpark. J'utilise l'IDE PyCharm sur une machine Windows10. Pour la configuration, j'ai suivi les étapes suivantes :

  • installé PySpark
  • installé Java 8u211
  • téléchargé et collé le winutils.exe
  • a déclaré SPARK_HOME, JAVA_HOME et HADOOP_HOME dans Path.
  • ajout du dossier "spark" et des zips à la racine du contenu
  • déjà essayé : export SPARK_LOCAL_IP="127.0.0.1" dans load-spark-env.sh et autres solutions liées aux noms d'hôtes

L'erreur ci-dessous se produit lors du démarrage depuis cmd (l'exécution depuis l'intérieur de PyCharm donne le même résultat). Comment puis-je la corriger ?

message d'erreur :

Python 3.7.1 (default, Dec 10 2018, 22:54:23) [MSC v.1915 64 bit (AMD64)] :: Anaconda, Inc. on win32  
Type "help", "copyright", "credits" or "license" for more information.  
19/05/14 21:33:19 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable  
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).  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 ERROR SparkContext: Error initializing SparkContext.  
java.net.BindException: Cannot assign requested address: bind: Service 'sparkDriver' failed after 16 retries (on a random free port)! Consider explicitly setting the appropriate binding address for the service 'sparkDriver' (for example spark.driver.bindAddress for SparkDriver) to the correct binding address.  
        at sun.nio.ch.Net.bind0(Native Method)  
        at sun.nio.ch.Net.bind(Unknown Source)  
        at sun.nio.ch.Net.bind(Unknown Source)  
        at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)  
        at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:128)  
        at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:558)  
        at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1283)  
        at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:501)  
        at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:486)  
        at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:989)  
        at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:254)  
        at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:364)  
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)  
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403)  
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)  
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)  
        at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)  
        at java.lang.Thread.run(Unknown Source)  
19/05/14 21:33:21 WARN SparkContext: Another SparkContext is being constructed (or threw an exception in its constructor).  This may indicate an error, since only one SparkContext may be running in this JVM (see SPARK-2243). The other SparkContext was created at:  
org.apache.spark.api.java.JavaSparkContext.<init>(JavaSparkContext.scala:58)  
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)  
sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)  
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)  
java.lang.reflect.Constructor.newInstance(Unknown Source)  
py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:247)  
py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)  
py4j.Gateway.invoke(Gateway.java:238)  
py4j.commands.ConstructorCommand.invokeConstructor(ConstructorCommand.java:80)  
py4j.commands.ConstructorCommand.execute(ConstructorCommand.java:69)  
py4j.GatewayConnection.run(GatewayConnection.java:238)  
java.lang.Thread.run(Unknown Source)  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'parkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 WARN Utils: Service 'sparkDriver' could not bind on a random free port. You may check whether configuring an appropriate binding address.  
19/05/14 21:33:21 ERROR SparkContext: Error initializing SparkContext.  
java.net.BindException: Cannot assign requested address: bind: Service 'sparkDriver' failed after 16 retries (on a random free port)! Consider explicitly setting the appropriate binding address for the service 'sparkDriver' (for example spark.driver.bindAddress for SparkDriver) to the correct binding address.  
        at sun.nio.ch.Net.bind0(Native Method)  
        at sun.nio.ch.Net.bind(Unknown Source)  
        at sun.nio.ch.Net.bind(Unknown Source)  
        at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)  
        at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:128)  
        at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:558)  
        at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1283)  
        at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:501)  
        at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:486)  
        at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:989)  
        at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:254)  
        at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:364)  
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)  
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403)  
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)  
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)  
        at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)  
        at java.lang.Thread.run(Unknown Source)  
W:\Spark\spark-2.4.3-bin-hadoop2.7\python\pyspark\shell.py:45: UserWarning: Failed to initialize Spark session.  
  warnings.warn("Failed to initialize Spark session.")  
Traceback (most recent call last):  
  File "W:\Spark\spark-2.4.3-bin-hadoop2.7\python\pyspark\shell.py", line 41, in <module>  
    spark = SparkSession._create_shell_session()  
  File "W:\Spark\spark-2.4.3-bin-hadoop2.7\python\pyspark\sql\session.py", line 583, in _create_shell_session  
    return SparkSession.builder.getOrCreate()  
  File "W:\Spark\spark-2.4.3-bin-hadoop2.7\python\pyspark\sql\session.py", line 173, in getOrCreate  
    sc = SparkContext.getOrCreate(sparkConf)  
  File "W:\Spark\spark-2.4.3-bin-hadoop2.7\python\pyspark\context.py", line 367, in getOrCreate  
    SparkContext(conf=conf or SparkConf())  
  File "W:\Spark\spark-2.4.3-bin-hadoop2.7\python\pyspark\context.py", line 136, in __init__  
    conf, jsc, profiler_cls)  
  File "W:\Spark\spark-2.4.3-bin-hadoop2.7\python\pyspark\context.py", line 198, in _do_init  
    self._jsc = jsc or self._initialize_context(self._conf._jconf)  
  File "W:\Spark\spark-2.4.3-bin-hadoop2.7\python\pyspark\context.py", line 306, in _initialize_context  
    return self._jvm.JavaSparkContext(jconf)  
  File "W:\Spark\spark-2.4.3-bin-hadoop2.7\python\lib\py4j-0.10.7-src.zip\py4j\java_gateway.py", line 1525, in __call__  
    answer, self._gateway_client, None, self._fqn)  
  File "W:\Spark\spark-2.4.3-bin-hadoop2.7\python\lib\py4j-0.10.7-src.zip\py4j\protocol.py", line 328, in get_return_value  
    format(target_id, ".", name), value)  
py4j.protocol.Py4JJavaError: An error occurred while calling None.org.apache.spark.api.java.JavaSparkContext.  
: java.net.BindException: Cannot assign requested address: bind: Service 'sparkDriver' failed after 16 retries (on a random free port)! Consider explicitly setting the appropriate binding address for the service 'sparkDriver' (for example spark.driver.bindAddress for SparkDriver) to the correct binding address.  
        at sun.nio.ch.Net.bind0(Native Method)  
        at sun.nio.ch.Net.bind(Unknown Source)  
        at sun.nio.ch.Net.bind(Unknown Source)  
        at sun.nio.ch.ServerSocketChannelImpl.bind(Unknown Source)  
        at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:128)  
        at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:558)  
        at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1283)  
        at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:501)  
        at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:486)  
        at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:989)  
        at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:254)  
        at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:364)  
        at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)  
        at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403)  
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)  
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)  
        at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)  
        at java.lang.Thread.run(Unknown Source)

8voto

Au cas où quelqu'un rencontrerait le même problème :

conf = pyspark.SparkConf().set('spark.driver.host','127.0.0.1')
sc = pyspark.SparkContext(master='local', appName='myAppName',conf=conf)

a fait l'affaire.

1voto

Doug E Fresh Points 11

Je ne sais pas pourquoi la réponse de Bishu a reçu un vote négatif -- c'est la bonne réponse pour les utilisateurs de Windows..... Cela a fonctionné pour moi.

Étapes de Windows

Pour les personnes qui ne savent pas comment désigner les variables système dans Windows, voici la marche à suivre :

  1. Dans un dossier ouvert (avec la fenêtre de navigation du dossier ouverte à gauche), localisez " Ce PC "
  2. Cliquez avec le bouton droit de la souris sur " Ce PC " et choisissez " Propriétés "
  3. Dans le menu de navigation de gauche, choisissez " Paramètres avancés du système "
  4. Dans ce nouveau menu, choisissez l'élément inférieur " Variables d'environnement... "
  5. Dans la 2ème fenêtre (en bas), choisissez " Nouveau... "
  6. Pour " Variable "Tapez : SPARK_LOCAL_IP
  7. Pour " Valeur "Tapez : localhost
  8. Note : il se peut que ce soit 127.0.0.1 ou une autre valeur sur votre système - vous devriez vraiment vérifier ce qui est indiqué dans ce fichier ici. C:\Windows\System32\Drivers\etc\hosts
  9. Une fois fait, laissez cette zone entière
  10. Note : seules les NOUVELLES invites cmd chargeront/reconnaîtront la nouvelle variable système. -- veuillez charger une autre invite cmd

-- J'espère que ça aidera

0voto

Bishu Points 11

Sur Windows

Créez une variable d'environnement comme ci-dessous

Variable -> SPARK_LOCAL_IP Valeur -> localhost

SistemesEz.com

SystemesEZ est une communauté de sysadmins où vous pouvez résoudre vos problèmes et vos doutes. Vous pouvez consulter les questions des autres sysadmins, poser vos propres questions ou résoudre celles des autres.

Powered by:

X