microsoft / python-in-excel

Python in Microsoft Excel
MIT License
490 stars 31 forks source link

Installing new / customized libraries #18

Open ManavCbs opened 10 months ago

ManavCbs commented 10 months ago

Hi,

is there any way to install more libraries using '!pip install [library]' as when I am trying to install any library, it says:

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f3acef51610>: Failed to establish a new connection: [Errno 111] Connection refused'))': /simple/xlwings/ WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f3acef51760>: Failed to establish a new connection: [Errno 111] Connection refused'))': /simple/xlwings/ WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f3acef51820>: Failed to establish a new connection: [Errno 111] Connection refused'))': /simple/xlwings/ WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f3acef519d0>: Failed to establish a new connection: [Errno 111] Connection refused'))': /simple/xlwings/ WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ProxyError('Cannot connect to proxy.', NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7f3acef51c10>: Failed to establish a new connection: [Errno 111] Connection refused'))': /simple/xlwings/ ERROR: Could not find a version that satisfies the requirement xlwings (from versions: none) ERROR: No matching distribution found for xlwings WARNING: There was an error checking the latest version of pip. 

keyur32 commented 10 months ago

Thank you for the feedback! We currently do not have a way to install custom libraries but something we have talked about. Any particular scenario you are interested in trying?

jflam commented 10 months ago

This is due to the security policy of the container denying outbound network traffic. We would love to offer a solution to this problem though, so stay tuned!

ManavCbs commented 10 months ago

Thanks for the update! Being a Financial Modeler, I was thinking that maybe we could create our own libraries which can be further used either internally or by our clients.

Also, just a thought, could there be a quick fix for this if we have Anaconda installed and in the Excel ribbon, we have an option to connect through local environment and then we can use our libraries to test and deploy accordingly. This will help us to better understand the flexibilities and in the meantime, Microsoft can release a secured way to install libraries on cloud?

ManavCbs commented 10 months ago

Thank you for the feedback! We currently do not have a way to install custom libraries but something we have talked about. Any particular scenario you are interested in trying?

Is there a way to use 'Plotly' library as I want to create some 3D interactive charts for financial models in excel itself?

jflam commented 9 months ago

Thanks for the update! Being a Financial Modeler, I was thinking that maybe we could create our own libraries which can be further used either internally or by our clients.

Also, just a thought, could there be a quick fix for this if we have Anaconda installed and in the Excel ribbon, we have an option to connect through local environment and then we can use our libraries to test and deploy accordingly. This will help us to better understand the flexibilities and in the meantime, Microsoft can release a secured way to install libraries on cloud?

Unfortunately this will expose you to the very issue that we're trying to avoid - local execution using your identity.

The really horrible hack that you can do for now is to copy and paste your libraries into the first sheet in your workbook. But you won't be able to import them so you'll need to adapt your code so that they're all global functions or declarations.

ManavCbs commented 9 months ago

Ok, no worries. Just had a thought of the way of Executing through local environment. However, it might be my lack of understanding but couldn't we just create a textbox option in Excel ribbon where the "Python (Preview)" option is and there we just need to reference a local environment path?

ISSUE:

Also, I can see that I can import plotly.express in excel but I am not able to see any chart output when I try to create a simple bar chart in Excel:

Plotly Chart Issue

jflam commented 9 months ago

One of the most common attack vectors is to send someone a malicious Excel workbook as an email attachment. When the victim opens the workbook, it executes a macro which installs a malicious payload, or exfiltrates data on that use to an attacker. If we did the same thing with Python in Excel attackers could send malicious workbooks that execute Python locally using your identity. Asking the user whether to "trust" the workbook is a non-starter because most users look at that button as a "do you want to work today?" question. I hope this clarifies your question.

On your second question about plotly - we don't support dynamic plots today - ones that emit Javascript, HTML and CSS which let you manipulate the plot by zooming, panning, selecting etc. That will come later. We should probably have some kind of error message instead of just returning NoneType. @keyur32 what do you think?

ManavCbs commented 9 months ago

Thanks, that was helpful!

I agree that it should show error or like "NA" for the libraries not active. Also, is there a way to see the additional libraries installed as I can see that plotly is installed but didn't knew unless I tested. So, maybe in the initialization, it can be reflected as comment which will show that the libraries are placed but either not active or imported:

image