简体   繁体   中英

How to change the source code in an installed python package?

I want to change the source code in a python package. Specifically, I would like to change the following line from the source code

I want to edit:

outputs_shape = outputs.shape.as_list()

To:

outputs_shape = tf.shape(outputs)

I know how to do this in google Colab, but I am running my code on a remote server.

If I don't want to create a virtual environment and don't have access to the files from where it is downloaded, is there a way ( python code ) to modify an imported package if it is originally installed as pip install tensorflow_probability ?

You can try this, you can get the path of module by just doing this:

>>> import mymodule
>>> print mymodule.__file__
'/path/to/mymodule.py'

And now you got the file, you can open file and edit it accordingly!

I don't know if this a best idea or not or it may not work or harm other things also, but I have answered it because I had already done/tested it. So.. I am suggesting you.

如果你认为这是一个普遍有益的改变,你可以发送 PR。

To get path of a Python module from bash command line:

python3 -c 'import mymod; print(mymod.__file__);'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM