LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-08-2011, 09:51 AM   #1
nishitmukesh
Member
 
Registered: Oct 2010
Posts: 39

Rep: Reputation: 0
Arrow Importing python script


Hi,
I am able to import file.py in my C program(main.c), but unable to import this file (https://github.com/rg3/youtube-dl/ra....09/youtube-dl)

....file.py....
#!/usr/bin/python2.4
print "hi"


....main.c....
#include<stdio.h>
#include<stdlib.h>
#include"/usr/include/python2.4/Python.h"
int main()
{
PyObject *pmod = NULL;
Py_Initialize();
PySys_SetPath(".");
pmod = PyImport_ImportModule("file to be imported");
if (pmod == NULL)
{
printf ("Import Failed\n");
return 0;
}
Py_DECREF(pmod);
Py_Finalize();
return 0;
}

im using centos5.5 with python2.4
using this command to run it: gcc -o output pythonembed.c -lpython2.4

any suggestions how can i import this script:
https://github.com/rg3/youtube-dl/ra....09/youtube-dl
 
Old 04-08-2011, 10:19 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,552

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
So what errors are you getting? I find it a little strange that you have gone from importing a 1 line script to something a lot more in depth which may have gotchas that a simple import
may not work with. Like, you have noticed that the initial #! is different and hence the script may not be supported by version 2.4 that you are using?
 
Old 04-11-2011, 01:34 AM   #3
nishitmukesh
Member
 
Registered: Oct 2010
Posts: 39

Original Poster
Rep: Reputation: 0
Hi Grail,
"Import failed" this is the error.
even if i change first line to #!/usr/bin/python2.4.
Error may be because of huge code, any alternate option which i can go through?

Thanks.
 
Old 04-11-2011, 02:30 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,552

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
So if it is import failed then you need to ascertain if it is the import in your C code or the imports within the script?
So my first suggestion would be to open a python prompt (simply type python at the command prompt) and then find all lines that start with the word import
in the python script and type them in one by one to see which one, if any, errors.

Then you can move onto your C code and check it at each point of execution to see if everything is performing as expected up until the import.
 
Old 04-11-2011, 02:56 AM   #5
nishitmukesh
Member
 
Registered: Oct 2010
Posts: 39

Original Poster
Rep: Reputation: 0
Hi,
All import statements within the script are working fine from python prompt and the entire script when run in individually is working fine.
But when embedded in C code error is generated, even for one line script (which uses only print statement) if i try to use import statement its giving Import failed.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Ubuntu 9.10 - Error importing python modules - $PYTHONPATH? km0r3 Linux - Software 4 12-06-2009 10:18 PM
swig 13.3.39, ubuntu 8.10, problem with importing C program to python plugo Linux - Software 3 08-11-2009 02:26 AM
swig 13.3.39, ubuntu 8.10, problem with importing C program to python plugo Linux - Software 1 08-09-2009 10:39 PM
Problem importing python module...cant install anything!!! bpedman Linux - Software 0 02-07-2007 09:02 PM
importing trouble....python...regarding Tkinter maseby Programming 0 11-03-2003 02:54 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration