简体   繁体   English

安装最新版Python应该在哪个目录下?

[英]Which directory should I be in when I install the newest version of Python?

I'm a beginner, trying to learn by doing.我是初学者,想边做边学。 I've learned a bit of Python and Django, and I'm starting a new project (recipe website.).我学到了一点 Python 和 Django,我正在开始一个新项目(食谱网站。)。 I read that I should be using virtual environments to isolate my projects from one another.我读到我应该使用虚拟环境将我的项目彼此隔离。 Following Corey Schafer's tutorial ( https://youtu.be/N5vscPTWKOk ) on virtual environments, I created a folder called Environments under my base Code folder (ie ~/code/Environments), then created a virtual environment called recipe_project within Environments.按照 Corey Schafer 的虚拟环境教程 ( https://youtu.be/N5vscPTWKOk ),我在基本代码文件夹(即 ~/code/Environments)下创建了一个名为 Environments 的文件夹,然后在 Environments 中创建了一个名为 recipe_project 的虚拟环境。

Edit: I am using Ubuntu 18.04, sorry for not specifying that before.编辑:我使用的是 Ubuntu 18.04,抱歉之前没有指定。

However, I have multiple versions of Python installed, in various folders because I don't know the correct location (is there a correct location?) to install them.但是,我在各种文件夹中安装了多个版本的 Python,因为我不知道安装它们的正确位置(是否有正确的位置?)。 Currently I have Python 3.8.3 in my Environments folder, that was the folder where I happened to be when I installed Python 3.8 from the command line.目前,我的 Environments 文件夹中有 Python 3.8.3,这是我从命令行安装 Python 3.8 时碰巧所在的文件夹。 I want to use Python 3.8 to develop my recipe website.我想使用 Python 3.8 来开发我的食谱网站。 Is there a way to specify that?有没有办法指定? Do I need to specify that?我需要指定吗?

Clarification : Please note that I am asking about the correct place to install Python , not the place to create my virtual environment(s).澄清:请注意,我询问的是安装Python的正确位置,而不是创建我的虚拟环境的位置。

I activated my recipe_project virtual environment, then typed in pip list and got:我激活了我的 recipe_project 虚拟环境,然后输入pip list并得到:

DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained.弃用:Python 2.7 已于 2020 年 1 月 1 日结束其生命周期。请升级您的 Python,因为不再维护 ZA7F5F35426B927411FC9231B563827。 pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip, can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-支持

Package Version Package版本


pip 20.1.1 pip 20.1.1

pkg-resources 0.0.0 pkg-资源 0.0.0

setuptools 44.1.1安装工具 44.1.1

wheel 0.34.2车轮 0.34.2

I also tried typing in python3 -m pip list because I read that you should be more specific when using pip.我还尝试输入python3 -m pip list ,因为我读到您在使用 pip 时应该更具体。 When I did that, the deprecation warning disappeared, but the package-version list reverted to the long list that appears if I'm outside my virtual environment.当我这样做时,弃用警告消失了,但如果我在虚拟环境之外,包版本列表会恢复为出现的长列表。

So:所以:

  1. Is there a way to get my virtual environment to only use Python 3/use Python 3 by default?有没有办法让我的虚拟环境默认只使用 Python 3/使用 Python 3? If I need to install a tool or something, please specify how to install it from the command line (such as do I need to use python3 -m, or another method) and also which folder I should be in when I install it.如果我需要安装工具什么的,请指定如何从命令行安装(比如我需要使用python3 -m,还是其他方法),以及安装时应该在哪个文件夹中。

  2. In general, which folder should I be in when I install new versions of Python?一般来说,安装新版本的 Python 时应该在哪个文件夹中?

Please try to explain it as simply as possible since I am a beginner.由于我是初学者,请尽量简单地解释它。 I've already spent several hours researching this but at least half of what I read went over my head.我已经花了几个小时研究这个,但至少有一半我读到的内容超出了我的想象。

Thanks a lot for your patience and understanding!非常感谢您的耐心和理解!

You can specify the version of python while creating a virtualenv by using the -p flag.您可以在使用-p标志创建 virtualenv 时指定 python 的版本。 Check this question to find out how many versions of python you have installed in your machine.检查问题以了解您的机器中安装了多少个版本的 python。 (See all the answers) (查看所有答案)

For windows you can simply run which python and it'll display all the versions of python you have installed provided their paths are added to the PATH env variable.对于 windows,您可以简单地运行which python ,它将显示您已安装的 python 的所有版本,前提是它们的路径已添加到PATH环境变量中。

$ virtualenv -p python3.8 venv

If you do a help on virtualenv and find the flag, this is what is shows.如果您对 virtualenv 进行帮助并找到标志,这就是显示的内容。

$ virtualenv --help
...
  -p py, --python py            target interpreter for which to create a virtual (either absolute path or identifier string) (default: /usr/bin/python3)
...

As for which folder you should be in.至于你应该在哪个文件夹。
It doesn't matter.没关系。
But, it is recommended that you create the virtualenv inside your project folder just to keep things together because it's just easier than keeping a virtualenv for a project elsewhere.但是,建议您在项目文件夹中创建 virtualenv 只是为了将所有东西放在一起,因为它比为其他地方的项目保留 virtualenv 更容易。

As long as you activate the virtualenv and then do your work, it doesn't matter where the virtualenv actually is.只要你激活 virtualenv 然后做你的工作,virtualenv 实际上在哪里并不重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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