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 createPython 2
environment whilevirtualenv3
is forPython 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
最满意答案
在这个老问题上跳伞,因为我遇到了同样的问题。
我有几乎完全相同的问题。 我听到了响应者的建议,即路线上发生了一些时髦的事情。 我挖到路线并找到(翻译以适合您的情况):
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 resemblesurl_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 insertscategory_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!
相关问答
更多-
#config/routes.rb resources :users do resources :images end 这是一个深度。 #config/routes.rb resources :users do resources :images do resources :comments end end 这不仅仅是一个层次。 正如您所引用的资源所看到的,问题不是无法匹配资源,而是处理流程。 例如... #app/controllers/comments_controll ...
-
Ruby on Rails 4无法使用form_for使用嵌套路由(Ruby on Rails 4 Can't get form_for working with nested routes)[2022-08-13]
请尝试以下代码 <%= form_for [@task.user, @task], method: :put do |f| %> Try the below code <%= form_for [@task.user, @task], method: :put do |f| %> -
Ruby on Rails - Rspec - 控制器测试 - 嵌套路由(Ruby on Rails - Rspec - Controller test - nested route)[2022-12-27]
您可以在应用程序根目录中使用rake routes或bundle exec rake routes查看Rails生成的rake routes 。 我在一个全新的rails应用程序中进行了相同的资源设置,并且rake路由输出如下(仅适用于订单详细信息路径): order_detail_storefront_order GET /storefronts/:storefront_id/orders/:id/order_detail(.:format) orders#o ... -
在这个老问题上跳伞,因为我遇到了同样的问题。 我有几乎完全相同的问题。 我听到了响应者的建议,即路线上发生了一些时髦的事情。 我挖到路线并找到(翻译以适合您的情况): resources :posts resources :categories do resources :posts end 这使得调用category_posts_path返回(如预期) /category/1/posts 。 然而,认识到will_paginate调用类似url_for东西是至关重要的, url_for从路由“向后” ...
-
在route.rb文件中尝试以下路由: # routes.rb Rails.application.routes.draw do namespace :stubs do #use namespace instead of scope namespace :api do resources :enpoints end end resources :auth match :api, to: 'api#index', via: :all match :stub ...
-
要获得博客的这种网址,我是否需要遵循嵌套路由。 不,您可以使用方法match来自己创建任何路线。 我可以在没有嵌套路由的情况下获得这种网址吗? 如果是,请给出一些解释。 用方法match , match 'articles/:article_id/comments/:id/edit' => 'comments#edit' 导轨指南中的更多信息 目前,我正在尝试实现嵌套路由(可能会在您的响应后更改)。 对于这种路由,我是否需要在“articles”文件夹中创建“comments”文件夹? 或者我可以直接在v ...
-
我有 map.resources :tv_summaries map.resources :tv_shows 所有这一切都在我的route.rb文件中评论这两行修复了问题。 I had map.resources :tv_summaries map.resources :tv_shows all the all up top in my route.rb file commenting those two line fixed the problem.
-
我从你的问题中了解到你正在尝试创建一个自定义渲染器,尽管我从未使用它,但为此你需要重写渲染器的链接方法。 这里是链接到原始代码可能会有所帮助 - https://github.com/voormedia/paginary/blob/master/lib/paginary/helpers/pagination_helper.rb What I understand from your question that you are trying to create a custom renderer, altho ...
-
你需要使用 resources :teams do resources :projects end 注意复数! resource产生一个没有id的单一路径。 与第一个修复不再相关。 You need to use resources :teams do resources :projects end Note the plural! resource produces a singular route without id. won't be relevant anymore with the ...
-
我有一个分页javascript文件 所以在我的index.html.erb文件中我添加了 <%=javascript_include_tag "pagination.js"%> 在pagination.js文件中 $(function(){ $(".pagination a").live("click", function() { $.get(this.href, null, null, "script"); return false; }); }); ...