【问题标题】:Rails Console not loading? y (Errno::ENOENT)Rails 控制台未加载? y (Errno::ENOENT)
【发布时间】:2013-02-07 19:56:19
【问题描述】:

当我尝试加载 rails 控制台时,我突然收到以下错误消息。我最近刚刚将数据库切换到 postgres,这给我带来了很多问题(尽管我必须承认我比 mysql 更喜欢它!),所以我假设这与此有关。有什么想法吗?

y (Errno::ENOENT)/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require': No such file or directory - /usr/local/lib/?
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `block in require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/processing.rb:3:in `<top (required)>'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `block in require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/base.rb:5:in `<top (required)>'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `block in require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:236:in `load_dependency'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/activesupport-3.2.10/lib/active_support/dependencies.rb:251:in `require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/sprockets-2.2.2/lib/sprockets/environment.rb:1:in `<top (required)>'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/actionpack-3.2.10/lib/sprockets/railtie.rb:23:in `block in <class:Railtie>'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/initializable.rb:30:in `instance_exec'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/initializable.rb:30:in `run'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/initializable.rb:55:in `block in run_initializers'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/initializable.rb:54:in `each'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/initializable.rb:54:in `run_initializers'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/application.rb:136:in `initialize!'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/railtie/configurable.rb:30:in `method_missing'
    from /Users/benyorke/rubystore/config/environment.rb:6:in `<top (required)>'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/application.rb:103:in `require'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/application.rb:103:in `require_environment!'
    from /usr/local/Cellar/ruby/1.9.3-p327/lib/ruby/gems/1.9.1/gems/railties-3.2.10/lib/rails/commands.rb:40:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'

【问题讨论】:

  • 你删除了什么吗?
  • 不,我使用自制软件安装它,然后将 pg 添加到 gemfile 并运行 bundle install 命令。我遇到的问题是 postgres 的自动加载,不需要删除任何内容
  • 您是否在 PATH 中添加了 postgres 标头/二进制文件? which postgres 说什么?

标签: ruby-on-rails ruby rails-console


【解决方案1】:

我相信这可能是 Ruby 1.9.3-p327 的一个错误,刚刚由 Ruby 1.9.3-p385 修复。升级到 1.9.3-p385 可以解决问题吗?

此错误消息中似乎很奇怪,并且与我一直遇到的问题类似,是路径末尾的问号:No such file or directory - /usr/local/lib/?。在几周前从 1.9.3-p194 升级到 1.9.3-p327 后,我收到了与 ruby​​ 的 require 和带有问号、符号或其他随机字符的路径相关的类似奇怪错误消息。但是,这些问题非常零星,而且我们大约在同一时间遇到了一些硬件故障,因此很难追查到。

今天,这个问题开始在一个特定的环境中持续发生,所以我能够进行一些额外的调试。更新到 1.9.3-p385 似乎已经修复了它,但鉴于我遇到的问题的零星性质,我并不完全 100% 这实际上是修复。我也不完全确定这是否与您遇到的问题相同。路径中的神秘问号只是让它看起来可能是相关的。以下是我们遇到的错误类型的几个示例:

No such file or directory - /srv/shared/rails/internal/admin/vendor/bun@

No such file or directory - /srv/shared/rails/internal/admin/vendor?

如果它与我遇到的相同问题完全相关,但 1.9.3-p385 升级无法解决它,请提供一些其他说明或探索:

  • 我今天能够在 1.9.3-p327 和 1.9.3-p374 上重现此问题。但是,1.9.3-p194、1.9.3-p286 和 1.9.3-p385 上似乎不存在该问题。
  • 您是否在 gem 加载路径中的任何位置使用符号链接?例如,我们使用 Bundler 将 gem 安装到每个应用程序内的本地 vendor/bundle 路径中。但vendor/bundle 实际上是指向另一个位置的符号链接(这与 Capistrano 部署设置有关)。我相信符号链接可能在起作用。在今天的测试中,如果我没有使用符号链接,那么问题在所有版本的 ruby​​ 上都消失了。
  • 你使用bundler-exec吗?在另一个偶尔发生此问题的情况下,绕过别名 bundler-exec 似乎也能神奇地解决问题,但今天的问题甚至没有触及 bundler-exec,所以我不太确定。
  • 大多数情况下,我们的问题是非常随机的(尝试运行相同命令几次后它会消失),但在少数情况下,问题会持续一个小时或更长时间才消失。
  • 有关我们系统的一些信息:
    • 64 位红帽企业 Linux 6
    • 捆绑器 1.2.3
    • Rubygems 1.2.5(也发生在 1.2.4 下)
    • rbenv

但就像我说的,这个问题也恰好与我们端的一些硬件磁盘故障和一般服务器不稳定同时发生,所以我不确定这是 Ruby 问题还是发生了什么。但希望 1.9.3-p385 能够真正修复它。

【讨论】:

  • 如果您仍然遇到错误,请查看我上面的帖子。抱歉,它没有指定问题,但它确实对我有用。最重要的是在我的机器上安装 postgres gem,即使我的 gemfile 只使用 pg gem
【解决方案2】:

很抱歉没有更新这个帖子 - 实际上我已经在后台工作了几个星期了。我在网上找不到任何关于此的信息,所以我将尽可能详细地发布解决方案。


问题

我遇到的问题是我无法访问 rails 控制台,并且每次重新启动机器时都必须手动启动 postgres 服务器。我的解决方案是,因为我已经使用了几个星期了

关于控制台我使用了 herokus 控制台。通过将我的应用推送到 heroku(这是免费的),我不仅可以在网络(任何机器)上查看它,而且可以在我的机器上运行

$ heroku run console

并访问控制台。现在这无论如何都不是一个完美的解决方案,因为我无法在我的机器上操作数据,但它救了我很多次

关于服务器我跑了

$ brew info postgres

这给了我手动重启服务器的命令

You should reload postgresql:
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist

解决方案

说实话,我已经运行了几十次我能找到的每个命令,今天才开始运行。我不知道我是否在打错字,以无效的顺序执行,混淆了 pg/postgres/postgresql 或什么,但我在下面所做的工作

使用此解决方案时,它将清除所有数据库。迁移将能够重建结构,但任何数据都会丢失

1。更新了 Homebrew

$ brew update

如果您没有自制软件,请查看此页面以获取安装说明(用很多东西拯救了我的脖子,包括 minimagick imagemagick 和 postgres!):http://mxcl.github.com/homebrew/

2。删除了 postgresql

$ brew rm postgresql --force

3。安装postgreql

$ brew install postgresql

这是引用 postgres 的第一步。在网上查找时,我遇到了使用 postgresql、postgres 和 pg 的命令。 Postgresql 指的是实际的 PostgreSQL 程序。 postgres 和 pg 是 ruby​​ gems,我们稍后会讲到

4。跑建议的命令

运行“$ brew install postgres”后,您会得到很多信息。确保通读它,因为它会建议运行哪些命令。使用这些建议来查找我在下面引用的命令。 如果您以后需要访问此信息,只需运行

$ brew info postgresql

初始化数据库

$ initdb file/path

设置自动启动器

$ cp file/path ~ LaunchAgents/file/path

首先启动 postgresql

$ launchctl load file/path
$ pg_ctl-D file/oath

5。下载 Postgres.app

虽然据我所知这似乎是多余的,但这就是让它在我的 mac 上工作的原因。访问http://postgresapp.com下载

6。安装 gems

有两个 gem - postgres 和 pg。我在我的 gemfile 中需要 pg 并运行了一个 bundle install 命令,但是它仍然给我带来了问题,直到我在我的机器上安装了 postgres - 即使我的 gemfile 中不需要它,rails 控制台似乎在没有至少安装的情况下无法工作

在gem文件中

gem 'pg'

在终端窗口中运行捆绑安装命令

$ bundle install

Sudo 安装 postgres gem

$ sudo gem install postgres

此时一切都应该正常工作。您应该可以重新启动机器并且没有任何问题!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-29
    • 1970-01-01
    • 2018-08-22
    • 2021-07-24
    • 2014-12-07
    • 2011-06-11
    • 2011-10-29
    相关资源
    最近更新 更多