how to import an extra python package while using pyspark shell










1















I need to import airflow library modules in Pyspark shell. I am including the module path in --py-files while logging in to Pyspark shell.



pyspark2 --py-files /nas/isg_prodops_work/ABO/abound/prod/anaconda/envs/nas_airflow/lib/python3.5/site-packages/airflow


But, still I am get the following error:



>>> from airflow.models import Variable
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named airflow.models


The directory structure of my module looks like this:



airflow
|-- __init__.py
|-- dag(directory)
|-- operators(directory)
|-- models.py









share|improve this question
























  • It seems you just wrote the path of the py file. you have to add the file name in the end of your path. pyspark2 --py-files /nas/isg_prodops_work/ABO/abound/prod/anaconda/envs/nas_airflow/lib/python3.5/site-packages/airflow/models.py

    – Ali AzG
    Nov 15 '18 at 15:40











  • I tried adding the py file also. That did not work either

    – Surabhi_ks
    Nov 16 '18 at 11:37











  • You have a .py that contains pyspark code and you want to run it with an additional .py file in your linux terminal, is that right?

    – Ali AzG
    Nov 16 '18 at 14:00












  • I need to import an entire package. The package has the .py file in it. Even if I include the .py file path directly its not importing.

    – Surabhi_ks
    Nov 19 '18 at 10:39











  • I've written an answer. please check that out!

    – Ali AzG
    Nov 19 '18 at 13:35















1















I need to import airflow library modules in Pyspark shell. I am including the module path in --py-files while logging in to Pyspark shell.



pyspark2 --py-files /nas/isg_prodops_work/ABO/abound/prod/anaconda/envs/nas_airflow/lib/python3.5/site-packages/airflow


But, still I am get the following error:



>>> from airflow.models import Variable
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named airflow.models


The directory structure of my module looks like this:



airflow
|-- __init__.py
|-- dag(directory)
|-- operators(directory)
|-- models.py









share|improve this question
























  • It seems you just wrote the path of the py file. you have to add the file name in the end of your path. pyspark2 --py-files /nas/isg_prodops_work/ABO/abound/prod/anaconda/envs/nas_airflow/lib/python3.5/site-packages/airflow/models.py

    – Ali AzG
    Nov 15 '18 at 15:40











  • I tried adding the py file also. That did not work either

    – Surabhi_ks
    Nov 16 '18 at 11:37











  • You have a .py that contains pyspark code and you want to run it with an additional .py file in your linux terminal, is that right?

    – Ali AzG
    Nov 16 '18 at 14:00












  • I need to import an entire package. The package has the .py file in it. Even if I include the .py file path directly its not importing.

    – Surabhi_ks
    Nov 19 '18 at 10:39











  • I've written an answer. please check that out!

    – Ali AzG
    Nov 19 '18 at 13:35













1












1








1








I need to import airflow library modules in Pyspark shell. I am including the module path in --py-files while logging in to Pyspark shell.



pyspark2 --py-files /nas/isg_prodops_work/ABO/abound/prod/anaconda/envs/nas_airflow/lib/python3.5/site-packages/airflow


But, still I am get the following error:



>>> from airflow.models import Variable
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named airflow.models


The directory structure of my module looks like this:



airflow
|-- __init__.py
|-- dag(directory)
|-- operators(directory)
|-- models.py









share|improve this question
















I need to import airflow library modules in Pyspark shell. I am including the module path in --py-files while logging in to Pyspark shell.



pyspark2 --py-files /nas/isg_prodops_work/ABO/abound/prod/anaconda/envs/nas_airflow/lib/python3.5/site-packages/airflow


But, still I am get the following error:



>>> from airflow.models import Variable
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named airflow.models


The directory structure of my module looks like this:



airflow
|-- __init__.py
|-- dag(directory)
|-- operators(directory)
|-- models.py






python pyspark airflow






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 12:40









Ali AzG

7131717




7131717










asked Nov 15 '18 at 13:21









Surabhi_ksSurabhi_ks

274




274












  • It seems you just wrote the path of the py file. you have to add the file name in the end of your path. pyspark2 --py-files /nas/isg_prodops_work/ABO/abound/prod/anaconda/envs/nas_airflow/lib/python3.5/site-packages/airflow/models.py

    – Ali AzG
    Nov 15 '18 at 15:40











  • I tried adding the py file also. That did not work either

    – Surabhi_ks
    Nov 16 '18 at 11:37











  • You have a .py that contains pyspark code and you want to run it with an additional .py file in your linux terminal, is that right?

    – Ali AzG
    Nov 16 '18 at 14:00












  • I need to import an entire package. The package has the .py file in it. Even if I include the .py file path directly its not importing.

    – Surabhi_ks
    Nov 19 '18 at 10:39











  • I've written an answer. please check that out!

    – Ali AzG
    Nov 19 '18 at 13:35

















  • It seems you just wrote the path of the py file. you have to add the file name in the end of your path. pyspark2 --py-files /nas/isg_prodops_work/ABO/abound/prod/anaconda/envs/nas_airflow/lib/python3.5/site-packages/airflow/models.py

    – Ali AzG
    Nov 15 '18 at 15:40











  • I tried adding the py file also. That did not work either

    – Surabhi_ks
    Nov 16 '18 at 11:37











  • You have a .py that contains pyspark code and you want to run it with an additional .py file in your linux terminal, is that right?

    – Ali AzG
    Nov 16 '18 at 14:00












  • I need to import an entire package. The package has the .py file in it. Even if I include the .py file path directly its not importing.

    – Surabhi_ks
    Nov 19 '18 at 10:39











  • I've written an answer. please check that out!

    – Ali AzG
    Nov 19 '18 at 13:35
















It seems you just wrote the path of the py file. you have to add the file name in the end of your path. pyspark2 --py-files /nas/isg_prodops_work/ABO/abound/prod/anaconda/envs/nas_airflow/lib/python3.5/site-packages/airflow/models.py

– Ali AzG
Nov 15 '18 at 15:40





It seems you just wrote the path of the py file. you have to add the file name in the end of your path. pyspark2 --py-files /nas/isg_prodops_work/ABO/abound/prod/anaconda/envs/nas_airflow/lib/python3.5/site-packages/airflow/models.py

– Ali AzG
Nov 15 '18 at 15:40













I tried adding the py file also. That did not work either

– Surabhi_ks
Nov 16 '18 at 11:37





I tried adding the py file also. That did not work either

– Surabhi_ks
Nov 16 '18 at 11:37













You have a .py that contains pyspark code and you want to run it with an additional .py file in your linux terminal, is that right?

– Ali AzG
Nov 16 '18 at 14:00






You have a .py that contains pyspark code and you want to run it with an additional .py file in your linux terminal, is that right?

– Ali AzG
Nov 16 '18 at 14:00














I need to import an entire package. The package has the .py file in it. Even if I include the .py file path directly its not importing.

– Surabhi_ks
Nov 19 '18 at 10:39





I need to import an entire package. The package has the .py file in it. Even if I include the .py file path directly its not importing.

– Surabhi_ks
Nov 19 '18 at 10:39













I've written an answer. please check that out!

– Ali AzG
Nov 19 '18 at 13:35





I've written an answer. please check that out!

– Ali AzG
Nov 19 '18 at 13:35












1 Answer
1






active

oldest

votes


















0














Try this command:



pyspark2 --py-files /nas/isg_prodops_work/ABO/abound/prod/anaconda/envs/nas_airflow/lib/python3.5/site-packages/airflow/models.py


and then import like this:



>>> from models import Variable





share|improve this answer























  • This is still giving ImportError: No module named models error

    – Surabhi_ks
    Nov 20 '18 at 11:10











  • Try with pyspark instead of pyspark2.

    – Ali AzG
    Nov 20 '18 at 14:23










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320443%2fhow-to-import-an-extra-python-package-while-using-pyspark-shell%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Try this command:



pyspark2 --py-files /nas/isg_prodops_work/ABO/abound/prod/anaconda/envs/nas_airflow/lib/python3.5/site-packages/airflow/models.py


and then import like this:



>>> from models import Variable





share|improve this answer























  • This is still giving ImportError: No module named models error

    – Surabhi_ks
    Nov 20 '18 at 11:10











  • Try with pyspark instead of pyspark2.

    – Ali AzG
    Nov 20 '18 at 14:23















0














Try this command:



pyspark2 --py-files /nas/isg_prodops_work/ABO/abound/prod/anaconda/envs/nas_airflow/lib/python3.5/site-packages/airflow/models.py


and then import like this:



>>> from models import Variable





share|improve this answer























  • This is still giving ImportError: No module named models error

    – Surabhi_ks
    Nov 20 '18 at 11:10











  • Try with pyspark instead of pyspark2.

    – Ali AzG
    Nov 20 '18 at 14:23













0












0








0







Try this command:



pyspark2 --py-files /nas/isg_prodops_work/ABO/abound/prod/anaconda/envs/nas_airflow/lib/python3.5/site-packages/airflow/models.py


and then import like this:



>>> from models import Variable





share|improve this answer













Try this command:



pyspark2 --py-files /nas/isg_prodops_work/ABO/abound/prod/anaconda/envs/nas_airflow/lib/python3.5/site-packages/airflow/models.py


and then import like this:



>>> from models import Variable






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 '18 at 10:53









Ali AzGAli AzG

7131717




7131717












  • This is still giving ImportError: No module named models error

    – Surabhi_ks
    Nov 20 '18 at 11:10











  • Try with pyspark instead of pyspark2.

    – Ali AzG
    Nov 20 '18 at 14:23

















  • This is still giving ImportError: No module named models error

    – Surabhi_ks
    Nov 20 '18 at 11:10











  • Try with pyspark instead of pyspark2.

    – Ali AzG
    Nov 20 '18 at 14:23
















This is still giving ImportError: No module named models error

– Surabhi_ks
Nov 20 '18 at 11:10





This is still giving ImportError: No module named models error

– Surabhi_ks
Nov 20 '18 at 11:10













Try with pyspark instead of pyspark2.

– Ali AzG
Nov 20 '18 at 14:23





Try with pyspark instead of pyspark2.

– Ali AzG
Nov 20 '18 at 14:23



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320443%2fhow-to-import-an-extra-python-package-while-using-pyspark-shell%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3

Museum of Modern and Contemporary Art of Trento and Rovereto