简体   繁体   English

巨蟒之战

[英]Battle of Pythons

I have learned Python long ago and when I was just installing Python (I might have done some mistakes on installing it), I have upgraded from 3.6 (32-bit) to 3.7.4 (64-bit).很久以前就学过Python,刚安装Python的时候(我可能在安装时犯了一些错误),我已经从3.6(32位)升级到3.7.4(64位)。 One day I have found that I have (by mistake?) installed 3.7 (64-bit), too.有一天,我发现我(错误地?)也安装了 3.7(64 位)。

Now I am working on some problem and sometimes I need to install some new libraries, for example, OpenCV for detecting and processing images.现在我正在解决一些问题,有时我需要安装一些新的库,例如用于检测和处理图像的 OpenCV。 But when I install something with 'pip', it installs it in the directory Python36-32.但是当我使用“pip”安装某些东西时,它会将它安装在 Python36-32 目录中。 I have Python IDLE 3.7.4, so there are constantly appearing errors between different Pythons.我有 Python IDLE 3.7.4,所以在不同的 Python 之间不断出现错误。 I have also deleted Python 3.6 (32-bit), but then I couldn't use 'pip' command anymore.我还删除了 Python 3.6(32 位),但后来我不能再使用 'pip' 命令了。 I have also tried to change environmental variables from Python36-32 to Python37-64.我还尝试将环境变量从 Python36-32 更改为 Python37-64。 I was chroming a lot but without success.我镀铬很多,但没有成功。

I am not very new in Python as programming, but I am just a newbie on a real understanding of how Python works (I mean there for example: what are the differences between different Pythons, what are environmental variables ...)我在 Python 编程方面并不是很新,但我只是一个真正了解 Python 工作原理的新手(我的意思是例如:不同 Python 之间有什么区别,什么是环境变量......)

In general : When I was a newbie on Python programming, I have (by mistake) installed 3 Python versions: 3.6 (32-bit), 3.7 (64-bit), and 3.7.4 (64-bit).一般情况:当我还是 Python 编程新手时,我(错误地)安装了 3 个 Python 版本:3.6(32 位)、3.7(64 位)和 3.7.4(64 位)。 My IDLE works in 3.7.4 (64-bit) and my 'pip' installs all the libraries into Python 3.6 (32-bit).我的 IDLE 在 3.7.4(64 位)下工作,我的“pip”将所有库安装到 Python 3.6(32 位)中。 My computer is the battlefield for a lot of Pythons.我的电脑是很多 Python 的战场。 I have no idea what to do.我不知道该怎么做。 Should I delete some version, change something ...我应该删除一些版本,改变一些东西......

Thank you very much for solving the problem!非常感谢您解决问题!

PS I have realized that for me this problem (battle of Pythons) is much harder than the problem on which I am doing. PS 我已经意识到对我来说这个问题(Python 之战)比我正在做的问题要困难得多。

I have a similar experience when I first using python before grad school.我在读研究生之前第一次使用 python 时也有类似的经历。 For me, it is because the OS I was using at the time, windows of course.对我来说,这是因为我当时使用的操作系统,当然是 windows。 Even now, I still feel windows is not a good OS for programming.即使是现在,我仍然觉得 windows 不是一个好的编程操作系统。 One library management solution ana(conda) helped me a lot.一种图书馆管理解决方案 ana(conda) 对我帮助很大。 Right now conda has GUI interface now, and it provides a much new-programmer friendly entry point for using python.现在 conda 现在有 GUI 界面,它提供了一个非常新的程序员友好的使用 python 的入口点。 Another huge leg-up during that time is the Jupyter notebook (used to called Ipython), it allows have a semi-console and WYSIWYG programming.在那段时间里另一个巨大的优势是 Jupyter notebook(过去称为 Ipython),它允许有一个半控制台和所见即所得的编程。 Right now, we all use debuggers, but still it is a very intuitive way to programming.现在,我们都使用调试器,但它仍然是一种非常直观的编程方式。

Hope this helps.希望这可以帮助。

Different versions of Python can coexist on your machine simultaneously.不同版本的 Python 可以同时共存于您的机器上。

Almost all operating systems include a system version of Python which is installed alongside the operating system and which should not be changed;几乎所有的操作系​​统都包含一个 Python 的系统版本,它与操作系统一起安装,不应更改; if you run the command python in your terminal out of the box, this is the version of Python you will get.如果您开箱即python在终端中运行命令python ,这就是您将获得的 Python 版本。 This system Python should not be modified, as doing so has the potential of breaking OS-installed tools and libraries that depend on it.不应修改此系统 Python,因为这样做有可能破坏依赖它的操作系统安装的工具和库。

Installing Python on your machine (via the Python website) sets up a new Python on your machine which has priority over system Python.在您的机器上安装 Python(通过 Python 网站)会在您的机器上设置一个新的 Python,它的优先级高于系统 Python。 However, this is an "prepend" process, not a "replace" process.但是,这是一个“前置”过程,而不是“替换”过程。 Each new version of Python installed will have priority over the previous versions.安装的每个新版本的 Python 都将优先于以前的版本。 But , if you try to import a package, and that package doesn't exist in your highest priority Python version, your computer will rifle through the old Python's module file-paths to try to find them.但是,如果您尝试导入一个包,而该包在您的最高优先级 Python 版本中不存在,您的计算机将遍历旧 Python 的模块文件路径以尝试找到它们。 This is bad because all of the sudden you are using packages from different versions of Python, which may break due to changes between language versions.这很糟糕,因为您突然使用了来自不同 Python 版本的包,这可能会因语言版本之间的变化而中断。

Best practice is to only ever install a single version of Python on your machine (besides the system Python), and then use virtualenv or conda to manage setting up new work environment.最佳实践是在您的机器上只安装一个版本的 Python(除了系统 Python),然后使用virtualenvconda来管理设置新的工作环境。 So you should install all versions of Python except for latest, and then learn how to use these tools to avoid environment problems.所以你应该安装除最新版本之外的所有 Python 版本,然后学习如何使用这些工具来避免环境问题。

This is the reason why virtual environments are encouraged these days.这就是为什么现在鼓励虚拟环境的原因。 Many modern ide like pycharm make it simple to have each project made in an virtual environment.许多像 pycharm 这样的现代 ide 使在虚拟环境中制作每个项目变得简单。 According to the python version you could install libraries which would not disturb any other projects or global environment/setting.根据 python 版本,您可以安装不会干扰任何其他项目或全局环境/设置的库。

So the best way to stay away from these kind of issues is the use of virtual environment.因此,远离此类问题的最佳方法是使用虚拟环境。 Hope this helps in further projects.希望这有助于进一步的项目。

This article was a good start for me https://realpython.com/python-virtual-environments-a-primer/这篇文章对我来说是一个好的开始https://realpython.com/python-virtual-environments-a-primer/

Would edit more links if I do find如果我找到了会编辑更多链接

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

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