问题
In a project, I have e.g. two different packages, How can I use the setup.py to install these two packages in the Google's Colab, so that I can import the packages?
回答1:
You can use !setup.py install
to do that.
Colab is just like a Jupyter notebook. Therefore, we can use the !
operator here to install any package in Colab. What !
actually does is, it tells the notebook cell that this line is not a Python code, its a command line script. So, to run any command line script in Colab, just add a !
preceding the line.
For example: !pip install tensorflow
. This will treat that line (here pip install tensorflow
) as a command prompt line and not some Python code. However, if you do this without adding the !
preceding the line, it'll throw up an error saying "invalid syntax".
But keep in mind that you'll have to upload the setup.py
file to your drive before doing this (preferably into the same folder where your notebook is).
Hope this answers your question :)
回答2:
lets say you want to install scipy,
Here is the code to install it
!pip install scipy
回答3:
Joining the party late, but just as a complement, I ran into some problems with Seaborn not so long ago, because CoLab installed a version with !pip that wasn't updated. In my specific case, I couldn't use Scatterplot, for example. The answer to this is below:
To install the module, all you need is:
!pip install seaborn
To upgrade it to the most updated version:
!pip install --upgrade seaborn
If you want to install a specific version
!pip install seaborn==0.9.0
I believe all the rules common to pip apply normally, so that pretty much should work.
回答4:
- Upload setup.py to drive.
- Mount the drive.
- Get the path of setup.py.
- !python PATH install.
来源:https://stackoverflow.com/questions/51342408/how-do-i-install-python-packages-in-googles-colab