首页 \ 问答 \ virtualenv如何创建不同的python环境?(How can virtualenv create different python environments?)

virtualenv如何创建不同的python环境?(How can virtualenv create different python environments?)

我的服务器有3个virtualenv脚本:

$ ls -lt virtual*
lrwxrwxrwx 1 root root  4 Nov 22 06:19 virtualbox -> VBox
-rwxr-xr-x 2 root root 55 Aug 14 19:34 virtualenv
-rwxr-xr-x 1 root root 55 Aug 14 19:34 virtualenv2
-rwxr-xr-x 2 root root 55 Aug 14 19:34 virtualenv3
$ cat virtualenv
#!/usr/bin/python3
import virtualenv
virtualenv.main()
$ cat virtualenv2
#!/usr/bin/python2
import virtualenv
virtualenv.main()
$ cat virtualenv3
#!/usr/bin/python3
import virtualenv
virtualenv.main()

我知道virtualenv2用于创建Python 2环境,而virtualenv3用于Python 3 。 但令我困惑的是为什么只需将/usr/bin/python2修改为shebang行中的/usr/bin/python3就能达到创建不同环境的效果? 它背后的魔力是什么?


My server has 3 virtualenv scripts:

$ ls -lt virtual*
lrwxrwxrwx 1 root root  4 Nov 22 06:19 virtualbox -> VBox
-rwxr-xr-x 2 root root 55 Aug 14 19:34 virtualenv
-rwxr-xr-x 1 root root 55 Aug 14 19:34 virtualenv2
-rwxr-xr-x 2 root root 55 Aug 14 19:34 virtualenv3
$ cat virtualenv
#!/usr/bin/python3
import virtualenv
virtualenv.main()
$ cat virtualenv2
#!/usr/bin/python2
import virtualenv
virtualenv.main()
$ cat virtualenv3
#!/usr/bin/python3
import virtualenv
virtualenv.main()

I know virtualenv2 is used to create Python 2 environment while virtualenv3 is for Python 3. But what confuses me is why just modify the /usr/bin/python2 to /usr/bin/python3 in shebang line can achieve the effect that create different environments? What is the magic behind it?


原文:https://stackoverflow.com/questions/41274579
更新时间:2022-09-21 09:09

最满意答案

在这个老问题上跳伞,因为我遇到了同样的问题。

我有几乎完全相同的问题。 我听到了响应者的建议,即路线上发生了一些时髦的事情。 我挖到路线并找到(翻译以适合您的情况):

resources :posts
resources :categories do
  resources :posts
end

这使得调用category_posts_path返回(如预期) /category/1/posts

然而,认识到will_paginate调用类似url_for东西是至关重要的, url_for从路由“向后”工作以找到匹配参数的第一条路径。

由于resources :posts出现在嵌套路由之上,因此它看到满足要求并且只插入category_id=1是查询字符串。

它为所有其他人“开箱即用”工作的原因是因为他们没有将嵌套资源单独列为独立资源。

删除它,你应该没事!


Parachuting in here on this old question because I encountered the same issue.

I had pretty much exactly the same problem. I followed the responders' advice that something funky was going on with the routes. I dug into the routes and found (translated to suit your situation):

resources :posts
resources :categories do
  resources :posts
end

This made it so that calling category_posts_path returned (as expected) /category/1/posts.

However, it's of pivotal importance to realize that will_paginate calls something that resembles url_for, which works "backwards" from the routes to find the first route that matches the parameters.

Since resources :posts appears above the nested route, it sees that that one satisfies the requirements and just inserts category_id=1 was a query string.

The reason it worked "out of the box" for everyone else was because they didn't have the nested resource separately listed as a standalone resource.

Remove that and you should be fine!

相关问答

更多

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。