如何更改 google colab 中的路径?
How to change the path in google colab?
我目前正在努力更好地熟悉 Google Colab 并将其用作 python 的编码环境。我正在尝试设置用于测试的 ipynb 脚本。作为其中的一部分,我正在尝试安装 pipenv。我正在按照 (https://docs.python-guide.org/dev/virtualenvs/#lower-level-virtualenv)
的指示进行操作
部分指示说明将路径从 ~/.local 更改为 ~/.local/bin。我用运行 命令:"!python -m site --user.base" 确定路径,结果返回"/root/.local" 我对Colab 不是很熟悉所以我不知道 bin 文件是否已经存在,或者我是否需要制作一个或其他东西。我也不确定什么是最安全的,以及在设置路径时应该遵循哪些关于 Colab 的最佳实践。通常,我通过 GUI 修改 windows 机器上的路径,而我以前从未使用过命令行来更改它。在此先感谢知道如何执行此操作的任何人。
好的,这是我在尝试安装 pipenv 时从 Google Collaboratory 收到的错误消息的副本:
WARNING: The script virtualenv is installed in '/root/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script virtualenv-clone is installed in '/root/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts pipenv and pipenv-resolver are installed in '/root/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
因为我不太确定这些警告是什么意思,所以我 运行 pipenv install 命令无论如何:
!pipenv install requests
这导致了一条错误消息,基本上是说找不到命令 pipenv。
我没有任何在 Colab 中或从命令行设置路径变量的经验,所以我查看了另一个用户 [link] 的以下 Whosebug 问题:How can I insert path (environmental variable) for geckodriver in goggle colab? 到尝试了解如何去做。查看之后,我 运行 以下命令:
!cp /root/.local/bin /usr/local
这导致了一条自动评论:
cp: -r not specified; omitting directory '/root/.local/bin'
正如我之前所说,我没有任何从命令行设置系统变量的经验,而且我所读到的所有关于它的内容都带有警告,内容如下:未能正确执行可能会永久损坏你的机器。所以我犹豫要不要加上“-r”标志。
在进行网络搜索后,我从该站点 [link]:https://superuser.com/questions/839719/why-is-r-recursive-necessary-when-copying-a-directory-in-linux/839749 找到了 -r(递归复制)标志的一个很好的解释,我 运行 以下命令:
!cp -r /root/.local/bin /usr/local
这运行平安无事我叫:
!pipenv install requests
成功! 运行 平安无事。
因为我想保存我正在编写的脚本的结果,所以我之前使用以下方法安装了一个虚拟驱动器:
from google.colab import drive
from google.colab import files
drive.mount('/content/drive')
我还在我的 google 驱动器中创建了一个新目录来保存这个脚本和任何未来的数据文件等...当我 运行 上面的代码和我不知道这是否会成为问题。我不太熟悉 Python 及其虚拟环境。如果有人知道这是否会成为问题,请随时给我发消息。感谢所有阅读此问题并尝试回答,甚至思考答案可能是什么的人。
我目前正在努力更好地熟悉 Google Colab 并将其用作 python 的编码环境。我正在尝试设置用于测试的 ipynb 脚本。作为其中的一部分,我正在尝试安装 pipenv。我正在按照 (https://docs.python-guide.org/dev/virtualenvs/#lower-level-virtualenv)
的指示进行操作部分指示说明将路径从 ~/.local 更改为 ~/.local/bin。我用运行 命令:"!python -m site --user.base" 确定路径,结果返回"/root/.local" 我对Colab 不是很熟悉所以我不知道 bin 文件是否已经存在,或者我是否需要制作一个或其他东西。我也不确定什么是最安全的,以及在设置路径时应该遵循哪些关于 Colab 的最佳实践。通常,我通过 GUI 修改 windows 机器上的路径,而我以前从未使用过命令行来更改它。在此先感谢知道如何执行此操作的任何人。
好的,这是我在尝试安装 pipenv 时从 Google Collaboratory 收到的错误消息的副本:
WARNING: The script virtualenv is installed in '/root/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The script virtualenv-clone is installed in '/root/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
WARNING: The scripts pipenv and pipenv-resolver are installed in '/root/.local/bin' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
因为我不太确定这些警告是什么意思,所以我 运行 pipenv install 命令无论如何:
!pipenv install requests
这导致了一条错误消息,基本上是说找不到命令 pipenv。
我没有任何在 Colab 中或从命令行设置路径变量的经验,所以我查看了另一个用户 [link] 的以下 Whosebug 问题:How can I insert path (environmental variable) for geckodriver in goggle colab? 到尝试了解如何去做。查看之后,我 运行 以下命令:
!cp /root/.local/bin /usr/local
这导致了一条自动评论:
cp: -r not specified; omitting directory '/root/.local/bin'
正如我之前所说,我没有任何从命令行设置系统变量的经验,而且我所读到的所有关于它的内容都带有警告,内容如下:未能正确执行可能会永久损坏你的机器。所以我犹豫要不要加上“-r”标志。
在进行网络搜索后,我从该站点 [link]:https://superuser.com/questions/839719/why-is-r-recursive-necessary-when-copying-a-directory-in-linux/839749 找到了 -r(递归复制)标志的一个很好的解释,我 运行 以下命令:
!cp -r /root/.local/bin /usr/local
这运行平安无事我叫:
!pipenv install requests
成功! 运行 平安无事。 因为我想保存我正在编写的脚本的结果,所以我之前使用以下方法安装了一个虚拟驱动器:
from google.colab import drive
from google.colab import files
drive.mount('/content/drive')
我还在我的 google 驱动器中创建了一个新目录来保存这个脚本和任何未来的数据文件等...当我 运行 上面的代码和我不知道这是否会成为问题。我不太熟悉 Python 及其虚拟环境。如果有人知道这是否会成为问题,请随时给我发消息。感谢所有阅读此问题并尝试回答,甚至思考答案可能是什么的人。