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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:28:12+00:00 2026-06-10T21:28:12+00:00

I have python file, for example, named blah.py, that I would like to have

  • 0

I have python file, for example, named blah.py, that I would like to have compiled then placed into another folder using cmake. Right now, I am capable of doing this with the following code in my cmake file:

ADD_CUSTOM_TARGET(output ALL /usr/bin/python -m py_compile src/blah.py
                  COMMAND /bin/mv src/blah.pyc build VERBATIM)

This is on ubuntu 12.04. This code works as intended; the only problem is that the python file is being compiled in the source directory, then being put in the build directory.

However, I can’t assume that this src directory will have read AND write privileges, meaning what I need to do is combine these two commands into one (compile the python file and place the compiled python file into my build directory, instead of compiling it in the src directory then moving it)

I’m sure there must be some way I could be using to specify where I would like this compiled code to be placed, but I can’t find any. Help would be greatly appreciated! 🙂

EDIT: This link may have a solution..not sure:

Can compiled bytecode files (.pyc) get generated in different directory?

  • 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-10T21:28:13+00:00Added an answer on June 10, 2026 at 9:28 pm

    I was typing out this answer, and then looked at your edited link. This same answer is given in one of the unaccepted answers: https://stackoverflow.com/a/611995/496445

    import py_compile
    py_compile.compile('/path/to/source/code.py', cfile='/path/to/build/code.pyc')
    

    To call this via a basic shell command you can format it like this:

    python -c "import py_compile; py_compile.compile('/path/to/source/code.py', cfile='/path/to/build/code.pyc')"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume I have a main script, main.py, that imports another python file with
I have the output of a file that I would like to make a
I have a python file that will not correctly perform an import. If I
I have a python program/file that I want to run repeatedly and calculate the
I have a Python script that reads through a text csv file and creates
I have an existing python script that, among other things checks a file against
I have an executable file, named, for example, resource.py . It is disposed in
I would like to be able to have a configuration file with an assortment
I have a python file testHTTPAuth.py which uses module deliciousapi and is kept in
I have a Python file with as content: import re import urllib class A(object):

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.