Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5952157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:38:28+00:00 2026-05-22T17:38:28+00:00

Why does Import[!python –version, Text] work on the commandline but not in the frontend

  • 0

Why does

Import["!python --version", "Text"]

work on the commandline but not in the frontend of Mathematica 8 (running on a Mac)?

Shell:

"Python 2.7.1 -- EPD 7.0-2 (64-bit)"

Frontend:

""

Update:

Ok, the path is not (really) the problem, as

Import["!which python", "Text"]

yields

"/usr/bin/python"

in the frontend and

"/Library/Frameworks/EPD64.framework/Versions/Current/bin/python"

in the shell (which is a different python version I have installed on my system). Nevertheless, neither

Import["!/usr/bin/python --version", "Text"]

nor

Import[
"!/Library/Frameworks/EPD64.framework/Versions/Current/bin/python --version",
"Text"]

yield the correct output in the frontend. But the usage of different shells in the frontend and the terminal version could be a hint to why Mathematica is misbehaving.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:38:29+00:00Added an answer on May 22, 2026 at 5:38 pm

    python --version writes its response to the standard error stream, but Import only captures the standard output stream. To see the response, redirect stderr to stdout. In most shells (even Windows), this can be achieved using the magic incantation 2>&1:

    Import["!python --version 2>&1", "Text"]
    

    Front-end Different From Command-line?

    The Import command appears to function differently when run in the command-line version of Mathematica, but appearances can be deceiving. Here is a transcript:

    $ math
    Mathematica 8.0 for Microsoft Windows (64-bit)
    Copyright 1988-2011 Wolfram Research, Inc.
    
    In[1]:= Import["!python --version","Text"]
    Python 2.6.4
    
    Out[1]=
    

    Note that Out[1] is blank. The version string appears in the transcript, but this is due to the fact that the standard error stream is being displayed in the terminal window, interspersed with the standard output from Mathematica. This is even more clear if we assign the result to a variable and (attempt to) suppress the output using ;:

    In[2]:= v=Import["!python --version","Text"];
    Python 2.6.4
    
    In[3]:= v
    
    Out[3]=
    

    There shouldn’t have been any output, but we still see the standard error stream displayed in the terminal window. v is blank, showing that the value of the Import expression was blank as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How does this import work, what file does it use? import _functools In python
The Boost documentation does not specify this. When I use boost::python::import , where exactly
I have two related Python 'import' questions. They are easily testable, but I want
In Python, what exactly does import * import? Does it import __init__.py found in
I am running Cygwin Python version 2.5.2. I have a three-line source file, called
The code #!/usr/bin/env python import MySQLdb print Content-Type: text/html print print <html><head><title>Books</title></head> print <body>
Python's access to environment variables does not accurately reflect the operating system's view of
When I compile the Python code below, I get IndentationError: unindent does not match
The following code does not have any errors when run script.py -f filename but
I don't know if this is an obvious bug, but while running a Python

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.