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 8942385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:30:09+00:00 2026-06-15T11:30:09+00:00

I’ve been running some python code on Windows which opens up another python program

  • 0

I’ve been running some python code on Windows which opens up another python program ‘main_plot.py’ using the following line…

subprocess.Popen(['C:\\python26\\python.exe ','main_plot.py','-n', str(number_of_cores),'-m', str(number_of_motors)])

I’ve tried to ssh into a Mac OS pc to run the same code but it doesn’t work because I think I need to change the path. This was my first guess…

subprocess.Popen(['python','main_plot.py','-n', str(number_of_cores),'-m', str(number_of_motors)])

but I get the error…
python: can’t open file ‘main_plot.py’: [Errno 2] No such file or directory

I’ve also tried

subprocess.Popen(['python','~/code/stochastic/main_plot.py','-n', str(number_of_cores),'-m', str(number_of_motors)])

but I get the same error.

I’ve checked that the file is in ‘~/code/stochastic’ and it is. I’m a bit stuck as what to do next

  • 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-06-15T11:30:10+00:00Added an answer on June 15, 2026 at 11:30 am

    The problem isn’t a difference between Windows and Mac; it’s that you’re only using ~ on Mac, and you can’t use ~ in a pathname.

    Put a different way, ~/code/stochastic/main_plot.py is not a real pathname—or, rather, it is, but it’s looking for a directory named ~ under the current directory, not your home directory. The shell turns that into the real pathname using tilde-expansion. Python can do tilde-expansion as well, but you have to ask it to do so explicitly.

    So, the solution is simple:

    subprocess.Popen(['python',
                      os.path.expanduser('~/code/stochastic/main_plot.py'),
                      '-n', str(number_of_cores),'-m', str(number_of_motors)])
    

    As Jeremy Roman points out in a comment, you can use ~ in paths if you use shell=True, because then Python will put all of your args together into a command line to pass to the shell, and the shell does handle ~. But you don’t want to do that. Just call expanduser.

    For future reference, the same thing is true for all the other kinds of expansion the shell does. You can’t do "${HOME}/foo", but you can do os.path.expandvars("${HOME}/foo"). You can’t do "foo$((1+1))bar"; you have to do something like "foo%sbar" % (1+1,). And so on.

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

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am reading a book about Javascript and jQuery and using one of the
I am trying to understand how to use SyndicationItem to display feed which is

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.